Support SIGINT signal on Windows
Currently, it's not possible to stop an event loop on Windows with CTRL+c
(SIGINT signal). The feature should be implemented in SelectorEventLoop and/or
ProactorEventLoop.
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.
Original issue reported on code.google.com by victor.s...@gmail.com on 16 Jul 2014 at 3:15