[Python-checkins] bpo-43406: Fix test_signal.test_stress_modifying_handlers() (GH-24815)
miss-islington
webhook-mailer at python.org
Wed Mar 10 09:49:36 EST 2021
https://github.com/python/cpython/commit/ac5e23c540f5ec20fc390c72e097e0fdaf8b7ac9
commit: ac5e23c540f5ec20fc390c72e097e0fdaf8b7ac9
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-03-10T06:49:27-08:00
summary:
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.
(cherry picked from commit 1fa17e8cc62775a2e34b158135ce8589f9394f03)
Co-authored-by: Victor Stinner <vstinner at python.org>
files:
M Lib/test/test_signal.py
diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py
index 865e0102637c2..758e292fd5e37 100644
--- a/Lib/test/test_signal.py
+++ b/Lib/test/test_signal.py
@@ -1272,11 +1272,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
@@ -1285,8 +1290,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
More information about the Python-checkins
mailing list