[issue42969] pthread_exit & PyThread_exit_thread from PyEval_RestoreThread etc. are harmful
Sam Gross
report at bugs.python.org
Mon Nov 15 17:28:59 EST 2021
Sam Gross <colesbury at gmail.com> added the comment:
The `pthread_exit` behavior has been a problem for PyTorch and related libraries since Python 3.9. The PyTorch team has tried working around the problems without success (i.e. they keep getting bug reports involving crashes in PyEval_SaveThread/RestoreThread).
The hang/paused the thread behavior suggested by jbms and gps seems like the only reliable option. This is also what the Java VM does when returning from native code and the JVM has exited.
I believe it's not difficult to hang a thread in a cross-platform way: create a mutex, acquire it in the main thread (before setting PyRuntime._finalizing), never release it. Other threads can acquire that same mutex to block until the application exits.
The crashes can occur even without daemon threads if the user presses ctrl-c while _thread_shutdown is running.
----------
nosy: +colesbury
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42969>
_______________________________________
More information about the Python-bugs-list
mailing list