Nathaniel Smith added the comment:

I haven't noticed the error in the wild because I don't use set_wakeup_fd on 
Linux/MacOS, because of this issue :-). But on MacOS literally all it would 
take is to receive two signals in quick succession, or to receive one signal at 
a moment when someone has recently scheduled a callback from a thread (which 
also writes to the wakeup fd). In principle it can also happen on Windows, but 
on Windows apparently the smallest buffer you get for a socketpair is like 500 
kilobytes, so it doesn't come up except in rather artificial situations.

And yes, a possible workaround is to use an artificially large buffer on 
Linux/MacOS as well. I'm not saying this is a huge showstopper. But it's silly 
for downstream libraries to carry around workarounds for issues in CPython when 
we could just fix CPython.

> If the pipe becomes full, you loose signals: it's an hard error. I decided to 
> log an error into fd 2 because in a signal handler, the number of allowed 
> functions is very limited.

This makes sense for asyncio, but not for most other async libraries in Python, 
because they *don't* lose signals when the pipe becomes full. That's why I'm 
suggesting that the signal module should have an option to let users decide 
whether they want the warning or not.

(It might also make sense to switch asyncio to stop using the fd as a 
communications channel. Theoretically this would be the ideal solution, but I 
understand why it's not a priority.)

> Related question: does asyncio support signals on Windows? I added support 
> for set_wakeup_fd() to Windows for asyncio, but then I forgot this TODO item 
> :-)

No, asyncio doesn't use set_wakeup_fd on Windows, so code like 
'loop.run_until_complete(asyncio.sleep(99999))' can't be interrupted. I'd 
appreciate if you could wait a few days to fix this though, because the blog 
post that I'm almost finished writing about signal handling currently uses this 
as an example of how trio is more awesome than asyncio ;-).

(This is a joke. Well, I mean, mostly. My draft does literally have that sleep 
example in it, but I won't be grumpy if you fix it first. Or at least, not 
*very* grumpy :-).)

----------

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

Reply via email to