Hi,

2014-07-16 10:58 GMT+02:00 Arve Knudsen <[email protected]>:
> Using Python 3.4.1 on Windows, I've found that while executing an asyncio
> event loop, programs ignore SIGINT. The workaround is to periodically wake
> up the event loop, so that SIGINT can be processed. Is this behaviour
> intentional? It's very confusing I think, and I'd rather not have to
> implement such a workaround. See my StackOverflow question/answer at
> http://stackoverflow.com/questions/24774980/why-cant-i-catch-sigint-when-asyncio-event-loop-is-running/.

add_signal_handler() and remove_signal_handler() are not implemented
yet on Windows:
https://docs.python.org/dev/library/asyncio-eventloops.html#platform-support


For SelectorEventLoop:

I tried to call "signal.set_wakeup_fd(self._csock.fileno())" where
self._csock is read end of the "self" pipe of the event loop, used to
wakeup the event loop on call_soon_threadsafe() or signals.

The problem is that set_wakeup_fd() expects a file, whereas
SelectorEventLoop uses a socket pair for the "self" pipe. Using a file
would be an issue with select.select() because it only supports
sockets...

I modified locally set_wakeup_fd() to use send() instead of write()
and accept sockets: it works!


For ProactorEventLoop:

There is an "Event" used by the C signal handler of Python: the event
is set when Python gets a SIGINT signal. The event is now private, but
it might be possible to retrieve it using ctypes or a modification of
Python 3.5.

It should be possible to register to event into the IOCP event loop to
wake up the event loop when the event is set. I didn't try to
implement it.


Until asyncio supports SIGINT on Windows, a workaround is to use a
periodic task to interrupt the event loop every N seconds.

Victor

Reply via email to