{{ message }}
gh-71052: Use raise_signal rather than kill in ThreadSignals.test_signals - #116423
Merged
Merged
Conversation
Member
Author
Member
Author
|
@vstinner: There's no CODEOWNERS entry for signals, but you've done some work in this area recently. Are you able to review this PR? |
vstinner
approved these changes
Mar 11, 2024
vstinner
left a comment
Member
There was a problem hiding this comment.
LGTM.
The change works as expected. I stressed the test with ./python -m test test_threadsignals -m test_signals -j250 -F . The system load was around 225.00 on a laptop with 12 logicial CPUs (6 cores), the test ran successfully 1676 times in 2 minutes.
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Mar 11, 2024
…ythonGH-116423) Use `raise_signal` rather than `kill` in `ThreadSignals.test_signals` (cherry picked from commit 34920f3) Co-authored-by: Malcolm Smith <smith@chaquo.com>
|
GH-116617 is a backport of this pull request to the 3.11 branch. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
Mar 11, 2024
…ythonGH-116423) Use `raise_signal` rather than `kill` in `ThreadSignals.test_signals` (cherry picked from commit 34920f3) Co-authored-by: Malcolm Smith <smith@chaquo.com>
|
GH-116618 is a backport of this pull request to the 3.12 branch. |
Member
|
Merged, thanks! |
This was referenced Mar 11, 2024
gvanrossum
added a commit
to gvanrossum/cpython
that referenced
this pull request
Mar 11, 2024
…hon#114432)" Reason: The new test doesn't always pass: python#116423 (comment) This reverts commit 1d0d49a.
adorilson
pushed a commit
to adorilson/cpython
that referenced
this pull request
Mar 25, 2024
…ython#116423) Use `raise_signal` rather than `kill` in `ThreadSignals.test_signals`
adorilson
pushed a commit
to adorilson/cpython
that referenced
this pull request
Mar 25, 2024
…ort}_clients (python#114432)" (python#116632) Revert "pythongh-113538: Add asycio.Server.{close,abort}_clients (python#114432)" Reason: The new test doesn't always pass: python#116423 (comment) This reverts commit 1d0d49a.
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this pull request
Apr 17, 2024
…ython#116423) Use `raise_signal` rather than `kill` in `ThreadSignals.test_signals`
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this pull request
Apr 17, 2024
…ort}_clients (python#114432)" (python#116632) Revert "pythongh-113538: Add asycio.Server.{close,abort}_clients (python#114432)" Reason: The new test doesn't always pass: python#116423 (comment) This reverts commit 1d0d49a.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

On Android, we run the test suite embedded in a standard app, in order to be representative of the environment where Python is most likely to be used. This means there's a native thread that uses
sigwaitto listen for SIGUSR1 in a loop, and responds by triggering the Java garbage collector and logging a message. This is only used for debugging purposes, and in most cases it doesn't matter because any signal handler will take priority over it.However, in
ThreadSignals.test_signalsthere's a background thread which sends both SIGUSR1 and SIGUSR2, and then immediately exits. So if the background thread is unavailable because it’s exited, and the main thread is unavailable because it’s already processing one of the signals (seecomplete_signalin kernel/signal.c), then the other signal may be delivered to Android’ssigwaitloop instead of the test's own handler. This happens about 1 time out of 4.This PR fixes that by sending the signals using
raise_signal(which is directed at the current thread) rather thanos.kill(which is directed at the whole process). Not only does this avoid the above scenario, it also strengthens the test by verifying that a signal which is delivered to a background thread, and not merely sent by it, still runs the Python-level handler on the main thread.Since
raise"shall not return until after the signal handler does", this also allows for the removal of a whole block of code which waits for the signal to arrive.