learningequality / kolibri-installer-android

Android wrapper for Kolibri.
MIT License
26 stars 22 forks source link

Ensure the task environment does not improperly cleanup the Python interpreter #132

Closed rtibbles closed 1 year ago

rtibbles commented 1 year ago

While working on https://github.com/learningequality/kolibri-installer-android/pull/119 it became apparent that when multiple tasks are run simultaneously on Android, that they can interfere with each other. This would happen because of the basic assumption built into Python for Android that within any process there was only a single thread using the Python interpreter. So far to address this, the following changes have been made in our fork of P4A and in the code in this repository:

Ultimately, it seems like in spite of the above attempts, the PyJnius error does persist - with some indications that even without an explicit teardown of the Python interpreter, it might be being garbage collected to free up memory when no tasks are running. What would be helpful in this case then is to ensure that the service is properly exited, to call System.exit in the process and cause it to be closed, thus emulating some of the prior defensive behaviour put in place in P4A and subsequent WorkManager integration work.