Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5471420

Browse files
authored
bpo-35601: Alleviate race condition when waiting for SIGALRM in test_asyncio (GH-11337)
There is a race condition regarding signal delivery in test_signal_handling_args for test_asyncio.test_events.KqueueEventLoopTests. The signal can be received at any moment outside the time window provided in the test. The fix is to wait for the signal to be received instead with a bigger timeout.
1 parent 4bc2467 commit 5471420

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

Lib/test/test_asyncio/test_events.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ def my_handler():
475475
self.loop.add_signal_handler(signal.SIGALRM, my_handler)
476476

477477
signal.setitimer(signal.ITIMER_REAL, 0.01, 0) # Send SIGALRM once.
478+
self.loop.call_later(60, self.loop.stop)
478479
self.loop.run_forever()
479480
self.assertEqual(caught, 1)
480481

@@ -487,11 +488,12 @@ def my_handler(*args):
487488
nonlocal caught
488489
caught += 1
489490
self.assertEqual(args, some_args)
491+
self.loop.stop()
490492

491493
self.loop.add_signal_handler(signal.SIGALRM, my_handler, *some_args)
492494

493495
signal.setitimer(signal.ITIMER_REAL, 0.1, 0) # Send SIGALRM once.
494-
self.loop.call_later(0.5, self.loop.stop)
496+
self.loop.call_later(60, self.loop.stop)
495497
self.loop.run_forever()
496498
self.assertEqual(caught, 1)
497499

0 commit comments

Comments
 (0)