[2.7] bpo-31334: Fix timeout in select.poll.poll() (GH-3277) (#4034) · python/cpython@27b951c (original) (raw)
4 files changed
lines changed
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -208,7 +208,7 @@ def test_threaded_poll(self): | ||
| 208 | 208 | @unittest.skipUnless(threading, 'Threading required for this test.') |
| 209 | 209 | @reap_threads |
| 210 | 210 | def test_poll_blocks_with_negative_ms(self): |
| 211 | -for timeout_ms in [None, -1, -1.0]: | |
| 211 | +for timeout_ms in [None, -1000, -1, -1.0]: | |
| 212 | 212 | # Create two file descriptors. This will be used to unlock |
| 213 | 213 | # the blocking call to poll.poll inside the thread |
| 214 | 214 | r, w = os.pipe() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -262,6 +262,7 @@ Brad Clements | ||
| 262 | 262 | Robbie Clemons |
| 263 | 263 | Steve Clift |
| 264 | 264 | Hervé Coatanhay |
| 265 | +Riccardo Coccioli | |
| 265 | 266 | Nick Coghlan |
| 266 | 267 | Josh Cogliati |
| 267 | 268 | Dave Cole |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 1 | +Fix ``poll.poll([timeout])`` in the ``select`` module for arbitrary negative | |
| 2 | +timeouts on all OSes where it can only be a non-negative integer or -1. | |
| 3 | +Patch by Riccardo Coccioli. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -530,6 +530,17 @@ poll_poll(pollObject *self, PyObject *args) | ||
| 530 | 530 | return NULL; |
| 531 | 531 | } |
| 532 | 532 | |
| 533 | +/* On some OSes, typically BSD-based ones, the timeout parameter of the | |
| 534 | + poll() syscall, when negative, must be exactly INFTIM, where defined, | |
| 535 | + or -1. See issue 31334. */ | |
| 536 | +if (timeout < 0) { | |
| 537 | +#ifdef INFTIM | |
| 538 | +timeout = INFTIM; | |
| 539 | +#else | |
| 540 | +timeout = -1; | |
| 541 | +#endif | |
| 542 | + } | |
| 543 | + | |
| 533 | 544 | /* Avoid concurrent poll() invocation, issue 8865 */ |
| 534 | 545 | if (self->poll_running) { |
| 535 | 546 | PyErr_SetString(PyExc_RuntimeError, |