New submission from Eric Snow <[email protected]>:
Currently when a thread acquires the GIL, it subsequently exits if the runtime
is finalizing. This helps with some cases like with stopping daemon threads.
This behavior should instead be triggered by the thread's interpreter
finalizing rather than the runtime. This implies the following changes:
* in Py_EndInterpreter() move "interp-finalizing = 1;" to right after the call
to "wait_for_thread_shutdown()"
* in Py_FinalizeEx() add "interp-finalizing = 1;" right after the call to
"wait_for_thread_shutdown()"
* update _PyEval_EvalFrameDefault() (the eval loop) to check
"interp->finalizing" instead of the runtime
* likewise update PyEval_RestoreThread() (as well as PyEval_AcquireThread() and
PyEval_AcquireLock(); see #36475)
The check will actually need to change from this:
if (_Py_IsFinalizing() && !_Py_CURRENTLY_FINALIZING(tstate)) {
to look like this:
if (interp->finalizing && !_Py_CURRENTLY_FINALIZING(tstate)) {
If we could guarantee that only the main thread will ever call Py_FinalizeEx()
then it would look more like this:
if (interp->finalizing && tstate.id != _PyRuntime.main_thread {
----------
components: Interpreter Core
messages: 339155
nosy: eric.snow
priority: normal
severity: normal
stage: needs patch
status: open
title: Exit threads when interpreter is finalizing rather than runtime.
type: behavior
versions: Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue36479>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com