Author vstinner
Recipients LewisGaul, eric.snow, maciej.szulik, mdk, nanjekyejoannah, ncoghlan, ned.deily, petr.viktorin, vstinner
Date 2020-06-15.16:36:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592238979.93.0.569973840859.issue36225@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2020-06-15 16:36:19vstinnersetrecipients: + vstinner, ncoghlan, ned.deily, petr.viktorin, eric.snow, maciej.szulik, mdk, nanjekyejoannah, LewisGaul
2020-06-15 16:36:19vstinnersetmessageid: <1592238979.93.0.569973840859.issue36225@roundup.psfhosted.org>
2020-06-15 16:36:19vstinnerlinkissue36225 messages
2020-06-15 16:36:19vstinnercreate