STINNER Victor <vstin...@python.org> added the comment:

I would not qualify the new Python 3.7 behavior (call Py_FatalError()) as a 
regression, so I remove "3.7regression" keyword.

Also, I don't think that we can easily fix this issue in a stable branch, I 
would prefer to start working on implementation this issue in the master 
branch, and only later consider to *maybe* backport the change. So I changed 
the Python version to "3.10".

I see multiple non trivial problems:

* To finalize the subinterpreter A, Py_Finalize() may switch the current Python 
thread state from the main interpreter to a Python thread in the subintrepeter 
A. It can lead to new funny issues.

* A subinterpreter can be stuck for whatever reason and refuse to stop. For 
example, the subinterpreter A may wait for an even from subinterpreter B. If we 
don't run two interpreters "in parallel" (in threads), it may be stuck forever.

* Python 3.10 still has weird code to allow daemon threads to continue to run 
after Py_Finalize() complete. Maybe we need to add such hacks for 
subinterpreter which fail to be finalized? For example, kill them (exit) as 
soon as they attempt to acquire the GIL. Search for tstate_must_exit() in 
Python/ceval_gil.h.


By the way, currently Py_Finalize() calls PyInterpreterState_Clear() which call 
object finalizers in the main thread of the main interpreter, whereas these 
finalizers might expect to be called from the thread which created them. I 
don't know if we must change anything else.

Again, all these problems are very complex :-(

The simple option, which is sadly a backward incompatible change, is to raise a 
fatal error in Py_Finalize() if a subinterpreter is still running.

Maybe we can start by logging a warning into stderr for now, before introducing 
the backward incompatible change. Maybe even only emit it when -X dev is used? 
https://docs.python.org/dev/library/devmode.html

----------
keywords:  -3.7regression
versions: +Python 3.10 -Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36225>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to