-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Subinterpreters don't properly clean up threads #128639
Copy link
Copy link
Closed
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-subinterpreterstype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtopic-subinterpreterstype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Projects
Status
Done
Crash report
What happened?
I found this issue a little while back, but I'm finally getting around to fixing it.
Currently, subinterpreter finalization assumes that there's only one thread left. So, any remaining threads--daemon or non-daemon--crash the interpreter upon finalizing:
This results in an assertion failure on my end:
So, there's a few things that need to get fixed:
Py_EndInterpreter, which will properly clean things up.PyThreadState_Delete. That should also happen inPy_EndInterpreter, after all threads have finished._PyRuntimeState_SetFinalizinghas been set, meaning that all threads will be already blocked, and thus cannot shutdown viathreading._shutdown, resulting in a deadlock.finalize_subinterpretersshould be called before that happens.CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs