Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ab27a9fc
Commit
ab27a9fc
authored
Jan 25, 2014
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asyncio: Fix race in FastChildWatcher (by its original author, Anthony Baire).
parent
669eeaf9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
20 deletions
+16
-20
Lib/asyncio/unix_events.py
Lib/asyncio/unix_events.py
+16
-20
No files found.
Lib/asyncio/unix_events.py
View file @
ab27a9fc
...
...
@@ -641,22 +641,16 @@ class FastChildWatcher(BaseChildWatcher):
def
add_child_handler
(
self
,
pid
,
callback
,
*
args
):
assert
self
.
_forks
,
"Must use the context manager"
with
self
.
_lock
:
try
:
returncode
=
self
.
_zombies
.
pop
(
pid
)
except
KeyError
:
# The child is running.
self
.
_callbacks
[
pid
]
=
callback
,
args
return
self
.
_callbacks
[
pid
]
=
callback
,
args
try
:
# Ensure that the child is not already terminated.
# (raise KeyError if still alive)
returncode
=
self
.
_zombies
.
pop
(
pid
)
# Child is dead, therefore we can fire the callback immediately.
# First we remove it from the dict.
# (raise KeyError if .remove_child_handler() was called in-between)
del
self
.
_callbacks
[
pid
]
except
KeyError
:
pass
else
:
callback
(
pid
,
returncode
,
*
args
)
# The child is dead already. We can fire the callback.
callback
(
pid
,
returncode
,
*
args
)
def
remove_child_handler
(
self
,
pid
):
try
:
...
...
@@ -681,16 +675,18 @@ class FastChildWatcher(BaseChildWatcher):
returncode
=
self
.
_compute_returncode
(
status
)
try
:
callback
,
args
=
self
.
_callbacks
.
pop
(
pid
)
except
KeyError
:
# unknown child
with
self
.
_lock
:
with
self
.
_lock
:
try
:
callback
,
args
=
self
.
_callbacks
.
pop
(
pid
)
except
KeyError
:
# unknown child
if
self
.
_forks
:
# It may not be registered yet.
self
.
_zombies
[
pid
]
=
returncode
continue
callback
=
None
if
callback
is
None
:
logger
.
warning
(
"Caught subprocess termination from unknown pid: "
"%d -> %d"
,
pid
,
returncode
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment