mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-31786: Make functions in the select module blocking when timeout is a small negative value. (#4003)
This commit is contained in:
parent
552be9d7e6
commit
2c15b29aea
7 changed files with 65 additions and 12 deletions
|
@ -204,6 +204,28 @@ class PollTests(unittest.TestCase):
|
|||
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, -0.1, -1e-100]:
|
||||
# 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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue