This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients gvanrossum, loewis, neologix, pitrou, vstinner, yselivanov
Date 2014-07-20.19:47:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>

I'm working on asyncio, someone asked why asyncio cannot be interrupted by CTRL+c (SIGINT):

On Windows, is not interrupted by CTRL+c. To get a reliable behaviour, interrupt on a signal, we can use signal.set_wakeup_fd(). New problem: on Windows, only supports sockets.

I propose to modify signal.set_wakeup_fd() to not only support files (use write), but also sockets (use send). Attached patch implements that.

This issue is part of a global PEP to modify how Python handles EINTR. I'm writing a PEP on that with Charles-François Natali. The idea to retry on EINTR in some cases, like write(), so we need a way to wakeup the code on a signal, on all platforms.


- I had to modify the pythoncore Visual Studio project to add a dependency to the WinSock library ("ws2_32.lib"). Is it a bad thing? We may split the _signal module into a new project, to only put the dependency there. What do you think? I'm not sure that it makes sense because the _signal module is always imported at Python startup, by initsigs() (search for the call to PyOS_InitInterrupts()).

- PySignal_SetWakeupFd() returns the old file descriptor, which is -1 by default. The API is not written to report errors. I chose to return -2 and clear the Python exception. Should we add a new function raising a Python exception on error? Ex: "int PySignal_SetWakeupFdWithError(int fd, int *old_fd)" returns 0 on success, -1 on error.

+        /* Import the _socket module to call WSAStartup() */
+        mod = PyImport_ImportModuleNoBlock("_socket");

I chose to import the _socket module because calling WSAStartup() requires also to call WSACleanup() at exit. I don't want to have two modules responsible for that.

I'm using "getsockopt(fd, SOL_SOCKET, SO_ERROR, ...)" to check if fd is a socket. Is there a better function to check if a file descriptor or handle is a socket?

According to the documentation, "GetFileType(handle) == FILE_TYPE_PIPE" is true for sockets, but also for (named and anonymous) pipes.
Date User Action Args
2014-07-20 19:47:14vstinnersetrecipients: + vstinner, gvanrossum, loewis, pitrou, neologix, yselivanov
2014-07-20 19:47:13vstinnersetmessageid: <>
2014-07-20 19:47:13vstinnerlinkissue22018 messages
2014-07-20 19:47:13vstinnercreate