Eric Snow <ericsnowcurren...@gmail.com> added the comment:

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! :)

----------

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

Reply via email to