Skip to content

Commit 660453b

Browse files
gh-158287: Simplify CLD_STOPPED handling in _ThreadedChildWatcher
1 parent 89c88cd commit 660453b

1 file changed

Lines changed: 6 additions & 16 deletions

File tree

‎Lib/asyncio/unix_events.py‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -973,22 +973,12 @@ def _do_waitpid(self, loop, expected_pid, callback, args):
973973
# On macOS, waitid() with WEXITED incorrectly returns stopped
974974
# child processes (si_code == CLD_STOPPED). Consume the stop
975975
# notification so we wait for actual process termination.
976-
if (
977-
res is not None
978-
and hasattr(os, 'CLD_STOPPED')
979-
and res.si_code in (os.CLD_STOPPED, getattr(os, 'CLD_TRAPPED', None))
980-
):
981-
consume_flags = getattr(os, 'WSTOPPED', 0)
982-
if hasattr(os, 'WCONTINUED'):
983-
consume_flags |= os.WCONTINUED
984-
if hasattr(os, 'WNOHANG'):
985-
consume_flags |= os.WNOHANG
986-
if consume_flags:
987-
try:
988-
os.waitid(os.P_PID, expected_pid, consume_flags)
989-
except ChildProcessError:
990-
pass
991-
continue
976+
if res.si_code == os.CLD_STOPPED:
977+
try:
978+
os.waitid(os.P_PID, expected_pid, os.WSTOPPED | os.WNOHANG)
979+
except ChildProcessError:
980+
pass
981+
continue
992982
break
993983
except ChildProcessError:
994984
# The child process is already reaped

0 commit comments

Comments
 (0)