Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple python interpreters per process #2609

Open
4 of 5 tasks
dbnicholson opened this issue May 31, 2022 · 1 comment
Open
4 of 5 tasks

Allow multiple python interpreters per process #2609

dbnicholson opened this issue May 31, 2022 · 1 comment

Comments

@dbnicholson
Copy link
Contributor

Checklist

  • the issue is indeed a bug and not a support request
  • issue doesn't already exist: https://github.com/kivy/python-for-android/issues
  • I have a short, runnable example that reproduces the issue
  • I reproduced the problem with the latest development version (p4a.branch = develop)
  • I used the grave accent (aka backticks) to format code or logs when appropriated

Versions

  • Python: 3.9
  • OS: Linux
  • Kivy: N/A
  • Cython: N/A
  • OpenJDK: 11

Description

Currently the native code starting the python interpreter only handles a single interpreter per process. This limits how applications handle services (and soon workers) as the python interpreter always has to be run in a separate process instead of a separate thread in the current process. This is managed in the AndroidManifest.xml file by declaring android:process in the service declarations.

Python does support this via sub-interpreters, but the setup is more complex. It would be nice to support that, though. Particularly for workers where they currently have to use more complex RemoteListenableWorker class.

@dbnicholson dbnicholson mentioned this issue Jun 1, 2022
4 tasks
@rtibbles
Copy link

@dbnicholson and I have talked about this separately, but just to add in from my experience of attempting to handle this, I think that it wouldn't even be necessary to support sub-interpreters (which is apparently somewhat finicky https://docs.python.org/3/c-api/init.html#bugs-and-caveats), but just properly register the non-Python created threads against the GIL.

However, in pursuing these approaches, I have come across an issue that seemingly is specific to PyJnius, whereby when it attempts to import its interface to Java from the pyi files, it results in an import not found error. The only possible interpretation that I have been able to come up with so far is that somehow the imported modules are garbage collected, because all Python threads have stopped, and this somehow does not get remedied when reinitializing Python in a subsequent invocation. I will report more here as I uncover it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants