This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aeros
Recipients aeros, eric.snow, ncoghlan, pitrou, tomMoral, vstinner
Date 2020-02-29.02:02:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1582941763.47.0.513169881402.issue37266@roundup.psfhosted.org>
In-reply-to
Content
> 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()`.
History
Date User Action Args
2020-02-29 02:02:43aerossetrecipients: + aeros, ncoghlan, pitrou, vstinner, eric.snow, tomMoral
2020-02-29 02:02:43aerossetmessageid: <1582941763.47.0.513169881402.issue37266@roundup.psfhosted.org>
2020-02-29 02:02:43aeroslinkissue37266 messages
2020-02-29 02:02:43aeroscreate