[Async-sig] Cancelling a coroutine from a signal handler?

Nathaniel Smith njs at pobox.com
Wed Apr 25 11:08:14 EDT 2018

On Wed, Apr 25, 2018, 06:34 Mark E. Haase <mehaase at gmail.com> wrote:

> This is also an interesting approach that I will experiment with. I guess
> this solves problem #1 (works on Windows) but not #2 (task stuck in loop),
> right? (The latter is a feature of all cooperative multitasking systems,
> yeah?)

If a task is hogging the loop, then you won't be able to shut down politely
using Task.cancel or similar. But if you're using signal.signal directly
then it would mean that your signal handler would still *run* while the
loop was blocked, so you'd at least have the option of escalating to
os._exit or similar.

I'm not sure I *really* advocate spawning a thread from your signal handler
just to call one loop method, but, hey, at least you know your options :-).

> Great blog post today! I really enjoy your writing style and Trio is
> really exciting.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/async-sig/attachments/20180425/e540f2a1/attachment-0001.html>

More information about the Async-sig mailing list