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 ncoghlan
Recipients eric.snow, nanjekyejoannah, ncoghlan, pablogsal, pconnell, pitrou, tim.peters, vstinner
Date 2019-12-31.05:50:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1577771456.75.0.707644904678.issue36476@roundup.psfhosted.org>
In-reply-to
Content
Perhaps we need a threading.throw() API, similar to the one we have for generators and coroutines?

If we had that, then Py_FinalizeEx() could gain a few new features:

* throw SystemExit into all daemon threads and then give them a chance to terminate before calling any atexit handlers (printing a warning if some of the threads don't exit)
* throw SystemExit into all daemon and non-daemon threads after running atexit handlers (printing a warning if any such threads exist at all, along with another warning if some of the threads don't exit)

Adding that would require an enhancement to the PendingCall machinery, though, since most pending calls are only processed in the main thread (there's no way to route them to specific child threads).

A simpler alternative would be to have an atomic "terminate_threads" counter in the ceval runtime state that was incremented to 1 to request that SystemExit be raised in daemon threads, and then to 2 to request that SystemExit be raised in all still running threads. When a thread received that request to exit, it would set a new flag in the thread state to indicate it was terminating, and then raise SystemExit. (The thread running Py_FinalizeEx would set that flag in advance so it wasn't affected, and other threads would use it to ensure they only raised SystemExit once). The runtime cost of this would just be another _Py_atomic_load_relaxed call in the eval_breaker branch. (Probably inside `make_pending_calls`, so it gets triggered both by the eval_breaker logic, and by explicit calls to `Py_MakePendingCalls`).
History
Date User Action Args
2019-12-31 05:50:56ncoghlansetrecipients: + ncoghlan, tim.peters, pitrou, vstinner, eric.snow, pconnell, pablogsal, nanjekyejoannah
2019-12-31 05:50:56ncoghlansetmessageid: <1577771456.75.0.707644904678.issue36476@roundup.psfhosted.org>
2019-12-31 05:50:56ncoghlanlinkissue36476 messages
2019-12-31 05:50:56ncoghlancreate