Message362960
> 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()`. |
|
Date |
User |
Action |
Args |
2020-02-29 02:02:43 | aeros | set | recipients:
+ aeros, ncoghlan, pitrou, vstinner, eric.snow, tomMoral |
2020-02-29 02:02:43 | aeros | set | messageid: <1582941763.47.0.513169881402.issue37266@roundup.psfhosted.org> |
2020-02-29 02:02:43 | aeros | link | issue37266 messages |
2020-02-29 02:02:43 | aeros | create | |
|