Commit 160999f
committed
Reap process and close pipe transports after _terminate_process_tree
_terminate_process_tree kills the OS process group / Job Object but does
not call process.wait() or close the anyio stdin/stdout pipe wrappers.
On Windows, the resulting _WindowsSubprocessTransport / PipeHandle objects
are GC'd after the test's filterwarnings scope has exited, triggering
PytestUnraisableExceptionWarning in whatever test runs next on the same
worker.
The old file-watching tests masked this because their ~1.8s of sleep()
calls per test gave the asyncio event loop's child watcher time to fire
_process_exited() callbacks (which close the transport) during the test.
The new socket-based tests are ~0.15s each — too fast for that callback
to fire before GC.
The SDK's production path (stdio.py:180) avoids this via 'async with
process:', whose __aexit__ handles reaping + stream closure. These tests
call _terminate_process_tree directly, so they must do the same cleanup
explicitly.
Added _terminate_and_reap() helper that runs unconditionally in each
test's finally: terminate tree (no-op if already dead), await wait()
to reap, close stdin/stdout pipe wrappers. Bounded by move_on_after(5).
Github-Issue: #17751 parent 324bbc2 commit 160999f
1 file changed
+33
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
311 | 312 | | |
312 | 313 | | |
313 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
314 | 341 | | |
315 | 342 | | |
316 | 343 | | |
| |||
335 | 362 | | |
336 | 363 | | |
337 | 364 | | |
338 | | - | |
339 | 365 | | |
340 | 366 | | |
341 | 367 | | |
342 | 368 | | |
343 | 369 | | |
344 | | - | |
345 | | - | |
346 | | - | |
| 370 | + | |
| 371 | + | |
347 | 372 | | |
348 | 373 | | |
349 | 374 | | |
| |||
378 | 403 | | |
379 | 404 | | |
380 | 405 | | |
381 | | - | |
382 | 406 | | |
383 | 407 | | |
384 | 408 | | |
385 | 409 | | |
386 | 410 | | |
387 | 411 | | |
388 | | - | |
389 | | - | |
390 | | - | |
| 412 | + | |
| 413 | + | |
391 | 414 | | |
392 | 415 | | |
393 | 416 | | |
| |||
420 | 443 | | |
421 | 444 | | |
422 | 445 | | |
423 | | - | |
424 | 446 | | |
425 | 447 | | |
426 | 448 | | |
427 | 449 | | |
428 | 450 | | |
429 | | - | |
430 | | - | |
431 | | - | |
| 451 | + | |
| 452 | + | |
432 | 453 | | |
433 | 454 | | |
434 | 455 | | |
| |||
0 commit comments