[issue33087] No reliable clean shutdown method

Josh Rosenberg report at bugs.python.org
Fri Mar 16 15:38:27 EDT 2018


Josh Rosenberg <shadowranger+python at gmail.com> added the comment:

To my knowledge, there is no safe way to do this for other threads for a reason.

If you make all your worker threads daemons, then they will terminate with the main thread, but they won't perform cleanup actions.

If you don't make them daemons, any "clean exit" procedure risks the threads choosing not to exit (even if you inject a SystemExit into every other thread, they might be in a try/except: or try/finally that suppresses it, or blocks waiting for something from another thread that has already exited, etc.). Exiting the thread that calls sys.exit() this way is considered okay, since you control when it is called, and it's up to you to do it at a safe place, but doing so asynchronously in other threads introduces all sorts of problems.

Basically, you want a reliable "shut down the process" and a reliable "clean up every thread", but anything that allows clean up in arbitrary threads also allows them to block your desired "shut down the process". Do you have a proposal for handling this?

----------
nosy: +josh.r

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33087>
_______________________________________


More information about the Python-bugs-list mailing list