Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c1a817

Browse files
[3.12]gh-71052: Useraise_signal inThreadSignals.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 commit34920f3)Co-authored-by: Malcolm Smith <smith@chaquo.com>
1 parentd130cb4 commit2c1a817

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

‎Lib/test/test_threadsignals.py‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,39 +32,28 @@ def handle_signals(sig,frame):
3232

3333
# a function that will be spawned as a separate thread.
3434
defsend_signals():
35-
os.kill(process_pid,signal.SIGUSR1)
36-
os.kill(process_pid,signal.SIGUSR2)
35+
# We use `raise_signal` rather than `kill` because:
36+
# * It verifies that a signal delivered to a background thread still has
37+
# its Python-level handler called on the main thread.
38+
# * It ensures the signal is handled before the thread exits.
39+
signal.raise_signal(signal.SIGUSR1)
40+
signal.raise_signal(signal.SIGUSR2)
3741
signalled_all.release()
3842

3943

4044
@threading_helper.requires_working_threading()
41-
@unittest.skipUnless(hasattr(signal,"alarm"),"test requires signal.alarm")
4245
classThreadSignals(unittest.TestCase):
4346

4447
deftest_signals(self):
4548
withthreading_helper.wait_threads_exit():
4649
# Test signal handling semantics of threads.
47-
# We spawn a thread, have the thread send two signals, and
50+
# We spawn a thread, have the thread senditselftwo signals, and
4851
# wait for it to finish. Check that we got both signals
4952
# and that they were run by the main thread.
5053
signalled_all.acquire()
5154
self.spawnSignallingThread()
5255
signalled_all.acquire()
5356

54-
# the signals that we asked the kernel to send
55-
# will come back, but we don't know when.
56-
# (it might even be after the thread exits
57-
# and might be out of order.) If we haven't seen
58-
# the signals yet, send yet another signal and
59-
# wait for it return.
60-
ifsignal_blackboard[signal.SIGUSR1]['tripped']==0 \
61-
orsignal_blackboard[signal.SIGUSR2]['tripped']==0:
62-
try:
63-
signal.alarm(1)
64-
signal.pause()
65-
finally:
66-
signal.alarm(0)
67-
6857
self.assertEqual(signal_blackboard[signal.SIGUSR1]['tripped'],1)
6958
self.assertEqual(signal_blackboard[signal.SIGUSR1]['tripped_by'],
7059
thread.get_ident())

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp