Commit a070356
committed
Guard double-terminate on returncode; make _terminate_and_reap idempotent
Addresses review feedback: calling _terminate_process_tree on an
already-reaped POSIX process hits the fallback path in
terminate_posix_process_tree (os.getpgid on a stale PID raises
ProcessLookupError), which emits two WARNING logs and an ERROR with
traceback. These are visible because pyproject.toml sets log_cli=true.
Previously, each test called _terminate_process_tree in the body and the
AsyncExitStack called _terminate_and_reap (which re-called
_terminate_process_tree) at exit — double-terminate, nine spurious log
records per run.
Fix: _terminate_and_reap now checks proc.returncode before terminating.
On POSIX, the asyncio child watcher sets returncode during
_terminate_process_tree's polling-loop yield, so by the time cleanup
runs it's populated and the guard skips the noisy re-terminate. On
Windows/FallbackProcess (no returncode attribute), getattr returns None
and terminate runs — but the Windows path is silent on double-call.
Restructured tests to call _terminate_and_reap (which wraps
_terminate_process_tree) as the action under test, and let the ExitStack
safety-net call it again. Since wait() and stream.aclose() are
idempotent, this is safe — and it covers both branches of the guard
(first call: returncode is None → terminate; second call: returncode set
→ skip). 100% coverage, still zero pragmas.
Github-Issue: #17751 parent 54295dd commit a070356
1 file changed
+15
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | | - | |
325 | | - | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
326 | 331 | | |
327 | 332 | | |
328 | | - | |
| 333 | + | |
| 334 | + | |
329 | 335 | | |
330 | 336 | | |
331 | 337 | | |
| |||
356 | 362 | | |
357 | 363 | | |
358 | 364 | | |
359 | | - | |
360 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
361 | 368 | | |
362 | 369 | | |
363 | 370 | | |
| |||
391 | 398 | | |
392 | 399 | | |
393 | 400 | | |
394 | | - | |
395 | | - | |
| 401 | + | |
| 402 | + | |
396 | 403 | | |
397 | 404 | | |
398 | 405 | | |
| |||
426 | 433 | | |
427 | 434 | | |
428 | 435 | | |
429 | | - | |
| 436 | + | |
430 | 437 | | |
431 | 438 | | |
432 | 439 | | |
| |||
0 commit comments