classification
Title: Runtime finalization assumes all other threads have exited.
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.snow
Priority: normal Keywords:

Created on 2019-03-29 20:38 by eric.snow, last changed 2019-03-29 20:40 by eric.snow.

Messages (2)
msg339143 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2019-03-29 20:38
Among the first 3 things that happen in Py_FinalizeEx() are, in order:

1. wait for all non-daemon threads (of the main interpreter) to finish
2. call registered atexit funcs
3. mark the runtime as finalizing

At that point the only remaining Python threads are:

* the main thread (where finalization is happening)
* daemon threads
* non-daemon threads created in atexit functions
* any threads belonging to subinterpreters

The next time any of those threads (aside from main) acquire the GIL, we expect that they will exit via a call to PyThread_exit_thread() (caveat: issue #36475).  However, we have no guarantee on when that will happen, if ever.  Such lingering threads can cause problems, including crashes and deadlock (see issue #36469).

I don't know what else we can do, beyond what we're already doing.  Any ideas?
msg339145 - (view) Author: Eric Snow (eric.snow) * (Python committer) Date: 2019-03-29 20:40
FYI, I've opened issue36477 to deal with the subinterpreters case.
History
Date User Action Args
2019-03-29 20:40:12eric.snowsetmessages: + msg339145
2019-03-29 20:38:26eric.snowcreate