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

Method _kill

Lib/test/libregrtest/run_workers.py:139–171  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

137 return '<%s>' % ' '.join(info)
138
139 def _kill(self) -> None:
140 popen = self._popen
141 if popen is None:
142 return
143
144 if self._killed:
145 return
146 self._killed = True
147
148 use_killpg = USE_PROCESS_GROUP
149 if use_killpg:
150 parent_sid = os.getsid(0)
151 sid = os.getsid(popen.pid)
152 use_killpg = (sid != parent_sid)
153
154 if use_killpg:
155 what = f"{self} process group"
156 else:
157 what = f"{self} process"
158
159 print(f"Kill {what}", file=sys.stderr, flush=True)
160 try:
161 if use_killpg:
162 os.killpg(popen.pid, signal.SIGKILL)
163 else:
164 popen.kill()
165 except ProcessLookupError:
166 # popen.kill(): the process completed, the WorkerThread thread
167 # read its exit status, but Popen.send_signal() read the returncode
168 # just before Popen.wait() set returncode.
169 pass
170 except OSError as exc:
171 print_warning(f"Failed to kill {what}: {exc!r}")
172
173 def stop(self) -> None:
174 # Method called from a different thread to stop this thread

Callers 2

stopMethod · 0.95
_run_processMethod · 0.95

Calls 2

print_warningFunction · 0.70
killMethod · 0.45

Tested by

no test coverage detected