mirror of
https://github.com/python/cpython.git
synced 2025-10-15 03:10:29 +00:00
bpo-38982: Fix asyncio PidfdChildWatcher on waitpid() error (GH-17477)
If waitpid() is called elsewhere, waitpid() call fails with ChildProcessError: use return code 255 in this case, and log a warning. It ensure that the pidfd file descriptor is closed if this error occurs.
This commit is contained in:
parent
b64334cb93
commit
e76ee1a72b
2 changed files with 18 additions and 2 deletions
|
@ -930,9 +930,20 @@ class PidfdChildWatcher(AbstractChildWatcher):
|
||||||
def _do_wait(self, pid):
|
def _do_wait(self, pid):
|
||||||
pidfd, callback, args = self._callbacks.pop(pid)
|
pidfd, callback, args = self._callbacks.pop(pid)
|
||||||
self._loop._remove_reader(pidfd)
|
self._loop._remove_reader(pidfd)
|
||||||
|
try:
|
||||||
_, status = os.waitpid(pid, 0)
|
_, status = os.waitpid(pid, 0)
|
||||||
os.close(pidfd)
|
except ChildProcessError:
|
||||||
|
# The child process is already reaped
|
||||||
|
# (may happen if waitpid() is called elsewhere).
|
||||||
|
returncode = 255
|
||||||
|
logger.warning(
|
||||||
|
"child process pid %d exit status already read: "
|
||||||
|
" will report returncode 255",
|
||||||
|
pid)
|
||||||
|
else:
|
||||||
returncode = _compute_returncode(status)
|
returncode = _compute_returncode(status)
|
||||||
|
|
||||||
|
os.close(pidfd)
|
||||||
callback(pid, returncode, *args)
|
callback(pid, returncode, *args)
|
||||||
|
|
||||||
def remove_child_handler(self, pid):
|
def remove_child_handler(self, pid):
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
Fix asyncio ``PidfdChildWatcher``: handle ``waitpid()`` error. If
|
||||||
|
``waitpid()`` is called elsewhere, ``waitpid()`` call fails with
|
||||||
|
:exc:`ChildProcessError`: use return code 255 in this case, and log a
|
||||||
|
warning. It ensures that the pidfd file descriptor is closed if this error
|
||||||
|
occurs.
|
Loading…
Add table
Add a link
Reference in a new issue