Skip to content

bpo-43406: Fix test_signal.test_stress_modifying_handlers() #24815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Lib/test/test_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1280,11 +1280,16 @@ def cycle_handlers():

old_handler = signal.signal(signum, custom_handler)
self.addCleanup(signal.signal, signum, old_handler)

t = threading.Thread(target=set_interrupts)
t.start()
try:
ignored = False
with support.catch_unraisable_exception() as cm:
t.start()
cycle_handlers()
do_stop = True
t.join()

if cm.unraisable is not None:
# An unraisable exception may be printed out when
# a signal is ignored due to the aforementioned
Expand All @@ -1293,8 +1298,13 @@ def cycle_handlers():
self.assertIn(
f"Signal {signum} ignored due to race condition",
str(cm.unraisable.exc_value))
# Sanity check that some signals were received, but not all
self.assertGreater(num_received_signals, 0)
ignored = True

# bpo-43406: Even if it is unlikely, it's technically possible that
# all signals were ignored because of race conditions.
if not ignored:
# Sanity check that some signals were received, but not all
self.assertGreater(num_received_signals, 0)
self.assertLess(num_received_signals, num_sent_signals)
finally:
do_stop = True
Expand Down