STINNER Victor added the comment: Ok, let's go with the option (B): use set_wakeup_fd() on all platforms, but only accept socket handles on Windows.
New patch wakeup_fd-7.patch: - signal.set_wakeup_fd() now only accepts socket handles (int) on Windows, it raises TypeError for files. Note: it also raises TypeError for closed sockets (I don't think that it's possible to check if a integer is a closed file descriptor or a closed socket). - PySignal_SetWakeupFd() uses Py_SAFE_DOWNCAST(wakeup.fd, SOCKET_T, int) to convert the socket handle to an int. It's safe according to msg223852. Sorry, it took me several versions to design the API. I discovered that: - files cannot be non-blocking on Windows (so signal.set_wakeu_fd() is almost useless on Windows in Python 3.4), - socket handles should be stored in SOCKET_T (not int) which caused me issues with the PySignal_SetWakeupFd() prototype (result type is int), - in fact, it's safe to cast SOCKET_T to int. Guido wrote: > My worry is that somehow a program has a fd that refers to both a file and a > socket. But I agree that changing the API is not a great option either. I don't think that it's possible that a file descriptor and a socket handle have the same value. ---------- Added file: http://bugs.python.org/file36071/wakeup_fd-7.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22018> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com