[Python-checkins] [2.7] bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (GH-4003). (#4031)

Serhiy Storchaka webhook-mailer at python.org
Wed Oct 18 04:28:41 EDT 2017


https://github.com/python/cpython/commit/ed267e3305a54eddae8106bdaae2c62d4c3b7db6
commit: ed267e3305a54eddae8106bdaae2c62d4c3b7db6
branch: 2.7
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-10-18T11:28:35+03:00
summary:

[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 2c15b29aea5d6b9c61aa42d2c24a07ff1edb4b46)

files:
M Lib/test/test_poll.py

diff --git a/Lib/test/test_poll.py b/Lib/test/test_poll.py
index 1e195ed624d..14dbfcf47b2 100644
--- a/Lib/test/test_poll.py
+++ b/Lib/test/test_poll.py
@@ -205,6 +205,28 @@ def test_threaded_poll(self):
             os.write(w, b'spam')
             t.join()
 
+    @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]:
+            # Create two file descriptors. This will be used to unlock
+            # the blocking call to poll.poll inside the thread
+            r, w = os.pipe()
+            pollster = select.poll()
+            pollster.register(r, select.POLLIN)
+
+            poll_thread = threading.Thread(target=pollster.poll, args=(timeout_ms,))
+            poll_thread.start()
+            poll_thread.join(timeout=0.1)
+            self.assertTrue(poll_thread.is_alive())
+
+            # Write to the pipe so pollster.poll unblocks and the thread ends.
+            os.write(w, b'spam')
+            poll_thread.join()
+            self.assertFalse(poll_thread.is_alive())
+            os.close(r)
+            os.close(w)
+
 
 def test_main():
     run_unittest(PollTests)



More information about the Python-checkins mailing list