-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
new_interpreter() should reuse more Py_InitializeFromConfig() code #83039
Comments
Currently, new_interpreter() is a subset of Py_InitializeFromConfig(): the code was duplicated. I would prefer that both functions stay in sync and so that new_interpreter() reuses more Py_InitializeFromConfig() code. |
This change introduced a reference leak: https://buildbot.python.org/all/#builders/80/builds/771 test_atexit leaked [792, 792, 792] references, sum=2376 It should be fixed by PR 17286. |
I associated this change to this issue because I had troubles when I tried to call _PyLong_Fini() in subinterpreters. I'm now trying to have different small integers per interpreter. |
I introduced a workaround to a reference leak in bpo-36854 because _PyImport_Cleanup() doesn't clear modules dictionary in some cases: Maybe _PyImport_Cleanup() should be enhanced to ensure that the dictionary of all modules is cleared when the function exit. |
Py_NewInterpreter() (new_interpreter() in practice) and Py_InitializeEx() now share almost all their code. Py_EndInterpreter() shares almost all its code with Py_Finalizer(). It's not perfect, but it's way better than previously. Py_NewInterpreter() now isolates more things from the main interpreter. For example, builtins and sys modules no longer copy the module dictionary of the main interpreter, but create their own dictionary from scratch. See each commit for the details. Py_Finalizer() could share more code with Py_EndInterpreter(), but each Py_Finalizer() change is really tricky and require to pay a lot attention. The Python finalization is really fragile. I started to take notes on this fragile code: I consider that the initial issue is fixed, so I close the issue. |
Thanks for working on this. It really does have far-reaching benefits, not just for the subinterpreter stuff I'm interested in. :) |
FYI this change broke librepo which calls PyLong_FromLong() without holding the GIL. In Python 3.8, "it works". In Python 3.9, it does crash: get_small_int() gets a NULL tstate and then dereference a NULL pointer. librepo bug: IMHO it's a bug in librepo: the GIL must be held to use Python C API. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: