8000 use return code of python script · rnixx/python-for-android@12a0f37 · GitHub
[go: up one dir, main page]

Skip to content

Commit 12a0f37

Browse files
committed
use return code of python script
1 parent f6fc1db commit 12a0f37

File tree

2 files changed

+17
-12
lines changed
  • pythonforandroid/bootstraps

2 files changed

+17
-12
lines changed

pythonforandroid/bootstraps/common/build/jni/application/src/start.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ int main_(int argc, char *argv[], int call_exit) {
358358
return ret;
359359
}
360360

361-
JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
361+
JNIEXPORT int JNICALL Java_org_kivy_android_PythonService_nativeStart(
362362
JNIEnv *env,
363363
jobject thiz,
364364
jstring j_android_private,
@@ -398,7 +398,7 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
398398
/* ANDROID_ARGUMENT points to service subdir,
399399
* so main() will run main.py from this dir
400400
*/
401-
main_(1, argv, 1);
401+
return main_(1, argv, 1);
402402
}
403403

404404
#if defined(BOOTSTRAP_NAME_SERVICELIBRARY)
@@ -442,7 +442,7 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonService_nativeStart(
442442
// main_(1, argv, 0);
443443
// }
444444

445-
JNIEXPORT void JNICALL Java_org_kivy_android_PythonWorker_nativeStart(
445+
JNIEXPORT int JNICALL Java_org_kivy_android_PythonWorker_nativeStart(
446446
JNIEnv *env,
447447
jobject thiz,
448448
jstring j_android_private,
@@ -483,10 +483,10 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonWorker_nativeStart(
483483
* so main() will run main.py from this dir
484484
*/
485485
// main_(1, argv, 1);
486-
main_(1, argv, 0);
486+
return main_(1, argv, 0);
487487
}
488488

489-
JNIEXPORT void JNICALL Java_org_kivy_android_PythonBoundService_nativeStart(
489+
JNIEXPORT int JNICALL Java_org_kivy_android_PythonBoundService_nativeStart(
490490
JNIEnv *env,
491491
jobject thiz,
492492
jstring j_android_private,
@@ -526,7 +526,7 @@ JNIEXPORT void JNICALL Java_org_kivy_android_PythonBoundService_nativeStart(
526526
/* ANDROID_ARGUMENT points to service subdir,
527527
* so main() will run main.py from this dir
528528
*/
529-
main_(1, argv, 1);
529+
return main_(1, argv, 1);
530530
}
531531
#endif
532532

@@ -550,7 +550,7 @@ void Java_org_kivy_android_PythonActivity_nativeSetenv(
550550
}
551551

552552

553-
void Java_org_kivy_android_PythonActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj)
553+
int Java_org_kivy_android_PythonActivity_nativeInit(JNIEnv* env, jclass cls, jobject obj)
554554
{
555555
/* This nativeInit follows SDL2 */
556556

@@ -566,7 +566,7 @@ void Java_org_kivy_android_PythonActivity_nativeInit(JNIEnv* env, jclass cls, jo
566566
argv[1] = NULL;
567567
/* status = SDL_main(1, argv); */
568568

569-
main_(1, argv, 1);
569+
return main_(1, argv, 1);
570570

571571
/* Do not issue an exit or the whole application will terminate instead of just the SDL thread */
572572
/* exit(status); */

pythonforandroid/bootstraps/service_library/build/src/main/java/org/kivy/android/PythonWorker.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public PythonWorker(
4444
@NonNull Context context,
4545
@NonNull WorkerParameters params) {
4646
super(context, params);
47+
Log.d("RemoteListenableWorker", "PythonWorker constructor");
4748

4849
appRoot = PythonUtil.getAppRoot(context);
4950

@@ -104,15 +105,19 @@ public void run() {
104105
new File(getApplicationContext().getApplicationInfo().nativeLibraryDir)
105106
);
106107

107-
nativeStart(
108+
int res = nativeStart(
108109
androidPrivate, androidArgument,
109110
workerEntrypoint, pythonName,
110111
pythonHome, pythonPath,
111112
pythonServiceArgument
112113
);
113114

114-
workCompleter.set(Result.success());
115-
Log.d("python worker", "PythonWorker thread terminating");
115+
if (res == 0) {
116+
workCompleter.set(Result.success());
117+
} else {
118+
workCompleter.set(Result.failure());
119+
}
120+
Log.d("python worker", "PythonWorker thread terminating:" + res);
116121
}
117122

118123
// Native part
@@ -126,7 +131,7 @@ public void run() {
126131
// Native part
127132
// synchronized is still needed, startRemoteWork gets called on the same service instance
128133
// XXX: check out how to start a service for each worker
129-
public static synchronized native void nativeStart(
134+
public static synchronized native int nativeStart(
130135
String androidPrivate, String androidArgument,
131136
String workerEntrypoint, String pythonName,
132137
String pythonHome, String pythonPath,

0 commit comments

Comments
 (0)
0