Commit 903cc56
committed
Reap and close spawned processes inside the child cleanup tests
The cleanup tests killed the spawned process tree but never awaited the
process or closed its pipe streams. The asyncio subprocess transports
stayed referenced by the per-test event loop, became garbage once that
loop closed, and were finalized during a later test on the same worker.
Under filterwarnings=error the resulting ResourceWarning fails whichever
test happens to be running; on Windows the warning itself can die inside
the transport repr with 'I/O operation on closed pipe'. A gc.collect()
inside the test cannot help because the transports are still referenced
by the live event loop at that point.
After the stop-of-writes check confirms the tree is dead, each test now
waits on the process (bounded, tolerant of the already-exited process),
closes stdin, drains stdout to EOF so the event loop observes the pipe
closure and can close the subprocess transport, then closes stdout. The
same disposal runs in the failure-path cleanup after its kill. Draining
works for both process flavors used on the platforms (anyio Process and
the Windows FallbackProcess, which has no aclose), and EOF is guaranteed
because every process that inherited the pipe handle is already dead.1 parent 8fe1f69 commit 903cc56
1 file changed
Lines changed: 47 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
265 | 267 | | |
266 | 268 | | |
267 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
268 | 303 | | |
269 | 304 | | |
270 | 305 | | |
| |||
354 | 389 | | |
355 | 390 | | |
356 | 391 | | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
357 | 395 | | |
358 | 396 | | |
359 | 397 | | |
| 398 | + | |
360 | 399 | | |
361 | 400 | | |
362 | 401 | | |
| |||
443 | 482 | | |
444 | 483 | | |
445 | 484 | | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
446 | 488 | | |
447 | 489 | | |
448 | 490 | | |
| 491 | + | |
449 | 492 | | |
450 | 493 | | |
451 | 494 | | |
| |||
514 | 557 | | |
515 | 558 | | |
516 | 559 | | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
517 | 563 | | |
518 | 564 | | |
519 | 565 | | |
| 566 | + | |
520 | 567 | | |
521 | 568 | | |
522 | 569 | | |
| |||
0 commit comments