Kyle Stanley <aeros...@gmail.com> added the comment:

> The daemon thread itself is not problematic, because ProcessPoolExecutor uses 
> an atexit hook to shutdown itself and therefore join the management thread.

ThreadPoolExecutor also uses an atexit hook for its shutdown process. Also, it 
sets each worker thread to a daemon. So we'd definitely have to address as well 
that prior to killing off daemon threads.

> Perhaps the solution would be to have an additional kind of atexit hooks, 
> which get executed before threads are joined.

Hmm, a potential way to do this might be adding a form of "atexit hook" support 
that's specific to threads. Each registered function would get called in the 
internal `_shutdown()` [1] function in the threading module, just before all of 
the non-daemon threads are joined. To me, this seems best implemented as a new 
public function for the threading module, perhaps something like 
`threading.register_atexit()`. Would this be reasonable?

---

[1] - IIUC, `threading._shutdown()` is called in pylifecycle.c, in 
`wait_for_thread_shutdown()`, which is the way that non-daemon threads are 
joined when the interpreter shuts down in `Py_EndInterpreter()` or is finalized 
in `Py_FinalizeEx()`.

----------

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

Reply via email to