This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients eric.snow, nanjekyejoannah, ncoghlan, vstinner
Date 2019-11-22.22:55:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1574463335.92.0.321219112237.issue38865@roundup.psfhosted.org>
In-reply-to
Content
tl;dr Py_Finalize() probably *should* only be allowed under the main interpreter.

As you know well, when the runtime starts we do it at first relative to a partially initialized main interpreter and the finish initialization with a fully operational main interpreter.  My expectation is that some of the global runtime state relies somehow on the main interpreter's state.  Consequently, finalization would then need to happen under the main interpreter.

The same idea applies to fork-without-exec, where we destroy all interpreters but the current one.  We now only allow os.fork() in the main interpreter.  So I'd expect the same treatement for finalization.

On the other hand, if the "main" interpreter isn't special after runtime init is done (i.e. a subinterpreter is effectively indistinguishable by nature) then it certainly would not matter which one finalizes (or is active during fork() for that matter).  On top of that, the effort we are making to identify the main interpreter (both in the code and in the docs) becomes unnecessary.

If we look at it from that angle, though, we do have cases where the main interpreter is still significant (regardless of the relationship between the main interpreter and the global runtime state).  At the very least, the main interpreter is solely responsible for some global resources, like signals.  So the main interpreter cannot go away until nothing else in the runtime relies on those resources.  I expect that we won't go down that route, which means finalization should happen only under the main interpreter.

Also keep in mind that this only matters relative to the C-API and I expect only embedders (not extensions) will be finalizing the runtime.  With PEP 554 the only case where you would run into problems is when running subinterpreters in daemon threads.  And we already know about problems with daemon threads during runtime finalization! :)
History
Date User Action Args
2019-11-22 22:55:35eric.snowsetrecipients: + eric.snow, ncoghlan, vstinner, nanjekyejoannah
2019-11-22 22:55:35eric.snowsetmessageid: <1574463335.92.0.321219112237.issue38865@roundup.psfhosted.org>
2019-11-22 22:55:35eric.snowlinkissue38865 messages
2019-11-22 22:55:35eric.snowcreate