[issue22018] Add a new signal.set_wakeup_socket() function

STINNER Victor report at bugs.python.org
Wed Jul 23 01:43:27 CEST 2014


STINNER Victor added the comment:

I talked with Charles-François. He doesn't like the idea of a new function because it would be harder to write portable code: which function should be used? signal.set_wakeup_fd() already works with sockets on UNIX.

Here is a new patch version 4 which tries to combine previous patchs:

- don't touch anything to existing code on UNIX. Keep the sig_atomic_t type for wakeup_fd and continue to use write() on sockets.

- on Windows, use a new "wakeup" structure to store the file descriptor or socket handle (use the  SOCKET_T type) and the last send() errors (errno and GetLastError())

- on Windows, use getsockopt(fd, SOL_SOCKET, SO_ERROR, ...) to check if fd is a socket: the function fails with WSAENOTSOCK if fd is not a socket.

- on Windows, PySignal_SetWakeupFd() only supports file descriptors. The function returns -1 if signal.set_wakeup_fd() was called with a socket handler, because the return type (int) is too small to store a socket handle (need type SOCKET_T) and we cannot change the prototype of this public API.

Reminder: the purpose of the whole patch is to be able to wakeup an event loop based on select.select() on Windows. select() only supports sockets on Windows.

Notes:

- we still need to add a dependency to the WinSock library

- the test are still skipped on Windows, I will work on a new patch to make the file descriptor or socket non-blocking and to run more wakeup fd tests on Windows

- if send() fails twice, the error is only reported once until report_wakeup_send_error() is called to consume the error. Anything, if send() failed, it will probably fail again quickly, there is no need to flood the terminal with these errors.

----------
Added file: http://bugs.python.org/file36038/signal_socket-4.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22018>
_______________________________________


More information about the Python-bugs-list mailing list