Repository navigation
bpo-33613, test_semaphore_tracker_sigint: fix race condition #7850
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
Changes from 1 commit
5f1df08
4f9babb
26d81a3
a7d5c59
a735d49
9460da4
fb136d0
f3d0f0b
f5e5cf9
4393021
d501f2f
9e0243e
26e077b
a50912b
bcbb942
0b46f07
66ef7dc
f7d2d4d
4a09fde
c9f96c1
c0a088c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…me process
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4473,19 +4473,24 @@ def check_semaphore_tracker_death(self, signum, should_die): | |
| # bpo-31310: if the semaphore tracker process has died, it should | ||
| # be restarted implicitly. | ||
| from multiprocessing.semaphore_tracker import _semaphore_tracker | ||
| pid = _semaphore_tracker._pid | ||
| if pid: | ||
| os.kill(pid, signal.SIGKILL) | ||
| time.sleep(0.5) # give it time to die | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to wait until the process completes instead of using a sleep?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sadly no AFAIK, because the tracker relies on calling
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can make the child capture
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not using os.waitpid() in the test, and modify ensure_running() to handle ChildProcessError? The purpose of the waitpid() call in ensure_running() is to check if the process died. We don't care of the exit status. Adding time.sleep(0.5) means adding a new race condition, while fixing another, no? |
||
| old_stderr = sys.stderr | ||
| r, w = os.pipe() | ||
| try: | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Notice that we cannot use |
||
| sys.stderr = open(w, "bw") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should be before the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in d075473 |
||
| _semaphore_tracker.ensure_running() | ||
| with warnings.catch_warnings(record=True) as all_warn: | ||
| _semaphore_tracker.ensure_running() | ||
| pid = _semaphore_tracker._pid | ||
| # Wait until we receive the PONG from the child, indicating that | ||
| # the signal handlers have been registered. See bpo-33613 for more | ||
| # information. | ||
| _semaphore_tracker._send("PING", "") | ||
| with open(r, "rb") as pipe: | ||
| data = pipe.readline() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we okay with this potentially hanging indefinitely if something goes wrong?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit d075473 implements a way to fail if reading takes too long. |
||
| if b"PON" not in data: | ||
| if b"PONG" not in data: | ||
| raise ValueError("Invalid data in stderr!") | ||
| finally: | ||
| sys.stderr.close() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the multiprocessing code uses "pid is not None". Technically, I'm not sure that it's possible to have a pid of 0, since pid 0 has a special meaning in many C functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
pid is not Nonehere. I think is clearer what the value you are expecting not to be.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now confused, you modified "if not pid" in the other file, whereas it seems like os.waitpid() doesn't return None.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I did not understand correctly your suggestion. For some reason, I inferred that with
WNOHANG,waitpidcould return None (aswaitidcan do if you provideWNOHANG). I think I understand now. Mea culpa :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 822516a1403d4eaec9ac743861336f0902d8186e