Skip to content

Commit ed267e3

Browse files
[2.7] bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (GH-4003). (#4031)
(cherry picked from commit 2c15b29)
1 parent 355393e commit ed267e3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎Lib/test/test_poll.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,28 @@ def test_threaded_poll(self):
205205
os.write(w, b'spam')
206206
t.join()
207207

208+
@unittest.skipUnless(threading, 'Threading required for this test.')
209+
@reap_threads
210+
def test_poll_blocks_with_negative_ms(self):
211+
for timeout_ms in [None, -1, -1.0]:
212+
# Create two file descriptors. This will be used to unlock
213+
# the blocking call to poll.poll inside the thread
214+
r, w = os.pipe()
215+
pollster = select.poll()
216+
pollster.register(r, select.POLLIN)
217+
218+
poll_thread = threading.Thread(target=pollster.poll, args=(timeout_ms,))
219+
poll_thread.start()
220+
poll_thread.join(timeout=0.1)
221+
self.assertTrue(poll_thread.is_alive())
222+
223+
# Write to the pipe so pollster.poll unblocks and the thread ends.
224+
os.write(w, b'spam')
225+
poll_thread.join()
226+
self.assertFalse(poll_thread.is_alive())
227+
os.close(r)
228+
os.close(w)
229+
208230

209231
def test_main():
210232
run_unittest(PollTests)

0 commit comments

Comments
 (0)