Always pass -1, or INFTIM where defined, to the poll() system call when
a negative timeout is passed to the poll.poll([timeout]) method in the
select module. Various OSes throw an error with arbitrary negative
values..
(cherry picked from commit
6cfa927ceb931ad968b5b03e4a2bffb64a8a0604)
@unittest.skipUnless(threading, 'Threading required for this test.')
@reap_threads
def test_poll_blocks_with_negative_ms(self):
- for timeout_ms in [None, -1, -1.0]:
+ for timeout_ms in [None, -1000, -1, -1.0]:
# Create two file descriptors. This will be used to unlock
# the blocking call to poll.poll inside the thread
r, w = os.pipe()
Robbie Clemons
Steve Clift
Hervé Coatanhay
+Riccardo Coccioli
Nick Coghlan
Josh Cogliati
Dave Cole
--- /dev/null
+Fix ``poll.poll([timeout])`` in the ``select`` module for arbitrary negative
+timeouts on all OSes where it can only be a non-negative integer or -1.
+Patch by Riccardo Coccioli.
return NULL;
}
+ /* On some OSes, typically BSD-based ones, the timeout parameter of the
+ poll() syscall, when negative, must be exactly INFTIM, where defined,
+ or -1. See issue 31334. */
+ if (timeout < 0) {
+#ifdef INFTIM
+ timeout = INFTIM;
+#else
+ timeout = -1;
+#endif
+ }
+
/* Avoid concurrent poll() invocation, issue 8865 */
if (self->poll_running) {
PyErr_SetString(PyExc_RuntimeError,