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 Riccardo Coccioli
Recipients Riccardo Coccioli, koobs, ned.deily, ronaldoussoren
Date 2017-09-03.22:21:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1504477302.52.0.907125806139.issue31334@psf.upfronthosting.co.za>
In-reply-to
Content
According to the Python documentation for the 'poll.poll([timeout])' method in the 'select' module, any negative value for the 'timeout' parameter is valid and should have the same behaviour [1]:
    "If timeout is omitted, negative, or None, the call will block until there is an event for this poll object."

Unfortunately, unlike the Linux, on many other OSes, including, but not limited to, macOS and {Free,Open,Net}BSD, the 'poll()' system call requires that the 'timeout' parameter is a non-negative integer or exactly -1 (sometimes defined as INFTIM). Any other negative value throws an error, see [2], [3], [4] and [5].

This is a snippet of code to reproduce the error:
#-----
import select

p = select.poll()
p.poll(-100)
#-----

Expected behaviour: block until there is an event for the poll object, in this case block indefinitely
Current behaviour on macOS and FreeBSD: OSError: [Errno 22] Invalid argument

I was able to reproduce the error on:
- macOS Sierra 10.12.6 with those Python versions: 3.3.6, 3.4.6, 3.5.3, 3.6.2, 3.7.0a0 (heads/master:2ef37607b7)
- FreeBSD 11.1 with Python 3.7.0a0 (heads/master:2ef37607b7)

On Linux this doesn't happen because the 'poll()' system call accept any negative value to wait indefinitely, see [6].
To adhere with the Python documentation described behaviour, I'm sending a pull request to propose to force the 'timeout' value passed to the 'poll()' system call to be exactly -1 (or INFTIM where defined) when a negative value is given.
This will not change the current behaviour on Linux and will have the behaviour described in the documentation on other OSes where is currently failing with an error.

[1] https://docs.python.org/3/library/select.html#poll-objects
[2] https://www.freebsd.org/cgi/man.cgi?poll
[3] https://man.openbsd.org/poll.2
[4] http://netbsd.gw.com/cgi-bin/man-cgi/man?poll
[5] From macOS 'man poll': "If timeout is greater than zero, it specifies a maximum interval (in milliseconds) to wait for any file descriptor to become ready. If timeout is zero, then poll() will return without blocking. If the value of timeout is -1, the poll blocks indefinitely."
[6] http://man7.org/linux/man-pages/man2/poll.2.html
History
Date User Action Args
2017-09-03 22:21:42Riccardo Cocciolisetrecipients: + Riccardo Coccioli, ronaldoussoren, ned.deily, koobs
2017-09-03 22:21:42Riccardo Cocciolisetmessageid: <1504477302.52.0.907125806139.issue31334@psf.upfronthosting.co.za>
2017-09-03 22:21:42Riccardo Cocciolilinkissue31334 messages
2017-09-03 22:21:42Riccardo Cocciolicreate