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

> I'm dealing with a subtle deadlock involving 
> concurrent.futures.ThreadPoolExecutor, and my solution that worked in Python 
> 3.8 broke with 3.9. I'm running some long-running (possibly infinite) tasks 
> in the thread pool, and I cancel them in an `atexit` callback so that 
> everything can shut down cleanly (before ThreadPoolExecutor joins all worker 
> threads in its own `atexit` hook).

IMO, a better practice would be providing those potentially infinite running 
tasks a direct method of escape and invoking it before calling 
executor.shutdown(), it would be a more reliable approach. But, perhaps there 
is some convenience utility in being able to provide custom atexit hooks. It 
also might help the user to separate the shutdown logic from the rest of the 
program. 

Since you worked with me in adding threading._register_atexit(), Do you have 
any thoughts, Antoine? I would personally not be opposed to it being made 
public assuming there's real utility present in doing so.

My only concern is that it might be a potential foot-gun. If the user submits 
an atexit hook that deadlocks, it might prevent threads from shutting down 
safely prior to interpreter finalization. I'm presently undecided if explicitly 
mentioning that it in the docs would be sufficient warning.

----------
nosy: +pitrou

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

Reply via email to