-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Legacy-mode subinterpreters in Python 3.12: import _tkinter
leads to shutdown crash
#115649
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
Comments
I can reproduce the issue with this Python code. import _xxsubinterpreters as interpreters
interp0 = interpreters.create(isolated = 0)
interp1 = interpreters.create(isolated = 0)
interpreters.run_string(interp0, 'import _tkinter')
interpreters.run_string(interp1, 'import _tkinter')
interpreters.destroy(interp0)
interpreters.destroy(interp1)
print('Successful!') Funnily enough, swapping the two interpreters.destroy(interp1)
interpreters.destroy(interp0) makes everything work as intended. |
I suspect, since this crash looks very similar to other crashes I've seen doing the same thing like #112292 and #112140 that There's a longer list of them here #112677 Why didn't this crash in older versions? because the sub interpreters implementation wasn't completed until 3.12 and so the state was global and not per-interpreter anyway. I'm assuming that if you set I think you should get that warning as well even with non-isolated sub interpreters since it will cause this type of crash CC @ericsnowcurrently |
In the main branch (c3b6dbf), no mater the destroy order, the interpreter will crash, this is a minimal code to reproduce it: import _interpreters
iid = _interpreters.create()
_interpreters.exec(iid, "import _tkinter")
_interpreters.destroy(iid)
I guess a lot codes have changed, so the original issue may be fixed, but another bug was introduces in #118157. |
…mport.c (#120315) Co-authored-by: Kumar Aditya <[email protected]>
…n in import.c (pythonGH-120315) (cherry picked from commit 28140d1) Co-authored-by: AN Long <[email protected]> Co-authored-by: Kumar Aditya <[email protected]>
…rn in import.c (GH-120315) (#120652) gh-115649: Copy the filename into main interpreter before intern in import.c (GH-120315) (cherry picked from commit 28140d1) Co-authored-by: AN Long <[email protected]> Co-authored-by: Kumar Aditya <[email protected]>
Is this still a problem? I just tried to reproduce the crash against main and it worked fine. |
I bisected with the reproducer and it seems to be fixed by 291cfa454b9c5b677c955aaf53fab91f0186b6fa. |
…n in import.c (python#120315) Co-authored-by: Kumar Aditya <[email protected]>
…n in import.c (python#120315) Co-authored-by: Kumar Aditya <[email protected]>
…n in import.c (python#120315) Co-authored-by: Kumar Aditya <[email protected]>
Bug report
Bug description:
Hello everyone,
I am working on an application embedding multiple Python subinterpreters - for which the Python version should be upgraded from Python 3.10 to Python 3.12.1. For the time being, the "legacy version" of subinterpreters (i.e., using a global, shared GIL) should be used, since all Python extensions (including
_tkinter
and all extensions with single-phase initialization) should be supported.If I understand the docs correctly, using the legacy
Py_NewInterpreter()
method should preserve the existing behavior. Still, the following application crashes at shutdown:When compiling and running this program with a debug build of Python 3.12.1 (or later) on Linux, I get this output:
With a non-debug build, the program exits with a segmentation fault.
The
gdb
backtrace looks as follows:Digging further into the backtrace, it looks like the Python garbage collector is trying to decrease the reference counter to the
_tkinter
module twice, despite it having been increased only once. Oddly enough, the program runs just fine when destroying the interpreters in reverse order:Can anyone help me shed some light into this issue? Is there anything I am overlooking?
CPython versions tested on:
3.12.1, 3.12.2, 3.13.0a4
Operating systems tested on:
Linux, Windows
Tasks
Linked PRs
The text was updated successfully, but these errors were encountered: