Author vstinner
Recipients gvanrossum, loewis, neologix, pitrou, python-dev, vstinner, yselivanov
Date 2014-07-24.19:46:17
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1406231178.97.0.291175083986.issue22018@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2014-07-24 19:46:19vstinnersetrecipients: + vstinner, gvanrossum, loewis, pitrou, neologix, python-dev, yselivanov
2014-07-24 19:46:18vstinnersetmessageid: <1406231178.97.0.291175083986.issue22018@psf.upfronthosting.co.za>
2014-07-24 19:46:18vstinnerlinkissue22018 messages
2014-07-24 19:46:17vstinnercreate