10000 bpo-43406: Fix test_signal.test_stress_modifying_handlers() (GH-24815) · python/cpython@1fa17e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1fa17e8

Browse files
authored
bpo-43406: Fix test_signal.test_stress_modifying_handlers() (GH-24815)
Fix a race condition of test_stress_modifying_handlers() of test_signal: only raise signals while we are in the catch_unraisable_exception() context manager. Moreover, don't check if we received at least one signal if at least one signal got ignored.
1 parent a9c03d7 commit 1fa17e8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Lib/test/test_signal.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,11 +1280,16 @@ def cycle_handlers():
12801280

12811281
old_handler = signal.signal(signum, custom_handler)
12821282
self.addCleanup(signal.signal, signum, old_handler)
1283+
12831284
t = threading.Thread(target=set_interrupts)
1284-
t.start()
12851285
try:
1286+
ignored = False
12861287
with support.catch_unraisable_exception() as cm:
1288+
t.start()
12871289
cycle_handlers()
1290+
do_stop = True
1291+
t.join()
1292+
12881293
if cm.unraisable is not None:
12891294
# An unraisable exception may be printed out when
12901295
# a signal is ignored due to the aforementioned
@@ -1293,8 +1298,13 @@ def cycle_handlers():
12931298
self.assertIn(
12941299
f"Signal {signum} ignored due to race condition",
12951300
str(cm.unraisable.exc_value))
1296-
# Sanity check that some signals were received, but not all
1297-
self.assertGreater(num_received_signals, 0)
1301+
ignored = True
1302+
1303+
# bpo-43406: Even if it is unlikely, it's technically possible that
1304+
# all signals were ignored because of race conditions.
1305+
if not ignored:
1306+
# Sanity check that some signals were received, but not all
1307+
self.assertGreater(num_received_signals, 0)
12981308
self.assertLess(num_received_signals, num_sent_signals)
12991309
finally:
13001310
do_stop = True

0 commit comments

Comments
 (0)
0