New submission from Riccardo Coccioli:

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

----------
components: Extension Modules, FreeBSD, macOS
messages: 301202
nosy: Riccardo Coccioli, koobs, ned.deily, ronaldoussoren
priority: normal
severity: normal
status: open
title: select.poll.poll fails on BSDs with arbitrary negative timeouts
type: behavior
versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue31334>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to