summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-03-11 21:09:42 (GMT)
committerGitHub <noreply@github.com>2024-03-11 21:09:42 (GMT)
commit2c1a81778dddbb8ee5e2ebd609d815dfe6735d18 (patch)
tree5c097a260520c399bec4d0adac4c4e6525e1bae9
parentd130cb49834573fff6a0a63da00e04d0a0cca818 (diff)
downloadcpython-2c1a81778dddbb8ee5e2ebd609d815dfe6735d18.zip
cpython-2c1a81778dddbb8ee5e2ebd609d815dfe6735d18.tar.gz
cpython-2c1a81778dddbb8ee5e2ebd609d815dfe6735d18.tar.bz2
[3.12] gh-71052: Use `raise_signal` in `ThreadSignals.test_signals` (GH-116423) (#116618)
gh-71052: Use `raise_signal` in `ThreadSignals.test_signals` (GH-116423) Use `raise_signal` rather than `kill` in `ThreadSignals.test_signals` (cherry picked from commit 34920f36917de0d4e658cf94992d53a5a7f27f51) Co-authored-by: Malcolm Smith <smith@chaquo.com>
-rw-r--r--Lib/test/test_threadsignals.py25
1 files changed, 7 insertions, 18 deletions
diff --git a/Lib/test/test_threadsignals.py b/Lib/test/test_threadsignals.py
index 6a53d65..bf241ad 100644
--- a/Lib/test/test_threadsignals.py
+++ b/Lib/test/test_threadsignals.py
@@ -32,39 +32,28 @@ def handle_signals(sig,frame):
# a function that will be spawned as a separate thread.
def send_signals():
- os.kill(process_pid, signal.SIGUSR1)
- os.kill(process_pid, signal.SIGUSR2)
+ # We use `raise_signal` rather than `kill` because:
+ # * It verifies that a signal delivered to a background thread still has
+ # its Python-level handler called on the main thread.
+ # * It ensures the signal is handled before the thread exits.
+ signal.raise_signal(signal.SIGUSR1)
+ signal.raise_signal(signal.SIGUSR2)
signalled_all.release()
@threading_helper.requires_working_threading()
-@unittest.skipUnless(hasattr(signal, "alarm"), "test requires signal.alarm")
class ThreadSignals(unittest.TestCase):
def test_signals(self):
with threading_helper.wait_threads_exit():
# Test signal handling semantics of threads.
- # We spawn a thread, have the thread send two signals, and
+ # We spawn a thread, have the thread send itself two signals, and
# wait for it to finish. Check that we got both signals
# and that they were run by the main thread.
signalled_all.acquire()
self.spawnSignallingThread()
signalled_all.acquire()
- # the signals that we asked the kernel to send
- # will come back, but we don't know when.
- # (it might even be after the thread exits
- # and might be out of order.) If we haven't seen
- # the signals yet, send yet another signal and
- # wait for it return.
- if signal_blackboard[signal.SIGUSR1]['tripped'] == 0 \
- or signal_blackboard[signal.SIGUSR2]['tripped'] == 0:
- try:
- signal.alarm(1)
- signal.pause()
- finally:
- signal.alarm(0)
-
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped'], 1)
self.assertEqual( signal_blackboard[signal.SIGUSR1]['tripped_by'],
thread.get_ident())