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 eric.snow
Recipients Ben.Darnell, aeros, eric.snow, pitrou, sa, vstinner
Date 2022-02-03.21:19:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643923142.6.0.840520381239.issue41962@roundup.psfhosted.org>
In-reply-to
Content
> I'm running some long-running (possibly infinite) tasks in the thread pool,
> and I cancel them in an `atexit` callback

To be clear, by "cancel" you are not talking about Future.cancel().  Rather, your handler causes all running tasks to finish (by sending a special message on the socket corresponding to each running task).  Is that right?

Some other things I inferred from your atexit handler:

* it does not make sure the task associated with the socket finishes (no way of knowing?)
* so if a task hangs while trying to stop then the running thread in the ThreadPoolExecutor would block shutdown forever
* similarly, if a task is stuck handling a request then it will never receive the special message on the socket, either blocking the send() in your handler or causing ThreadPoolExecutor shutdown/atexit to wait forever
* it vaguely implies a 1-to-1 relationship between sockets and *running* tasks
* likewise that pending (queued) tasks do not have an associated socket (until started)
* so once your handler finishes, any tasks pending in the ThreadPoolExecutor queue will eventually get started but never get stopped by your handler; thus you're back to the deadlock situation

Does all that sound right?  Most of that is relevant to some possible solutions I have in mind.
History
Date User Action Args
2022-02-03 21:19:02eric.snowsetrecipients: + eric.snow, pitrou, vstinner, sa, Ben.Darnell, aeros
2022-02-03 21:19:02eric.snowsetmessageid: <1643923142.6.0.840520381239.issue41962@roundup.psfhosted.org>
2022-02-03 21:19:02eric.snowlinkissue41962 messages
2022-02-03 21:19:02eric.snowcreate