<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Apr 24, 2018 at 9:54 PM, Nathaniel Smith <span dir="ltr"><<a href="mailto:njs@pobox.com" target="_blank">njs@pobox.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The simplest solution would be to use asyncio's native signal handler<br>
support instead of the signal module:<br>
<a href="https://docs.python.org/3/library/asyncio-eventloop.html#unix-signals" rel="noreferrer" target="_blank">https://docs.python.org/3/libr<wbr>ary/asyncio-eventloop.html#uni<wbr>x-signals</a><br></blockquote><div><br></div><div>Ahh, wow, I don't know how I missed this. I've been obsessing over coroutines and event loops for hours, now I realize that I misunderstood the voodoo in the signal module. Thank you for pointing me in this direction!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Alternatively, you can define a handler using signal.signal, and then<br></span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">arrange to re-enter the asyncio main loop yourself before calling<br></span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Task.cancel. I believe that the only guaranteed-to-be-safe way to do<br></span><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.8px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">this is:</span></blockquote><div><br></div><div>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?)</div><div><br></div><div>Great blog post today! I really enjoy your writing style and Trio is really exciting.</div><div><br></div><div>Cheers,</div><div>Mark</div></div></div></div>