MCPcopy Index your code
hub / github.com/python/cpython / _wait_pidfd

Method _wait_pidfd

Lib/subprocess.py:2104–2129  ·  view source on GitHub ↗

Wait for PID to terminate using pidfd_open() + poll(). Linux >= 5.3 only.

(self, timeout)

Source from the content-addressed store, hash-verified

2102 return (pid, sts)
2103
2104 def _wait_pidfd(self, timeout):
2105 """Wait for PID to terminate using pidfd_open() + poll().
2106 Linux >= 5.3 only.
2107 """
2108 if not _CAN_USE_PIDFD_OPEN:
2109 return False
2110 try:
2111 pidfd = os.pidfd_open(self.pid, 0)
2112 except OSError:
2113 # May be:
2114 # - ESRCH: no such process
2115 # - EMFILE, ENFILE: too many open files (usually 1024)
2116 # - ENODEV: anonymous inode filesystem not supported
2117 # - EPERM, EACCES, ENOSYS: undocumented; may happen if
2118 # blocked by security policy like SECCOMP
2119 return False
2120
2121 try:
2122 poller = select.poll()
2123 poller.register(pidfd, select.POLLIN)
2124 events = poller.poll(timeout * 1000)
2125 if not events:
2126 raise TimeoutExpired(self.args, timeout)
2127 return True
2128 finally:
2129 os.close(pidfd)
2130
2131 def _wait_kqueue(self, timeout):
2132 """Wait for PID to terminate using kqueue(). macOS and BSD only."""

Callers 1

_waitMethod · 0.95

Calls 4

TimeoutExpiredClass · 0.85
pollMethod · 0.45
registerMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected