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

Function reap_children

Lib/test/support/__init__.py:1521–1548  ·  view source on GitHub ↗

Use this function at the end of test_main() whenever sub-processes are started. This will help ensure that no extra children (zombies) stick around to hog resources and create problems when looking for refleaks.

()

Source from the content-addressed store, hash-verified

1519environment_altered = False
1520
1521def reap_children():
1522 """Use this function at the end of test_main() whenever sub-processes
1523 are started. This will help ensure that no extra children (zombies)
1524 stick around to hog resources and create problems when looking
1525 for refleaks.
1526 """
1527 global environment_altered
1528
1529 # Need os.waitpid(-1, os.WNOHANG): Windows is not supported
1530 if not (hasattr(os, 'waitpid') and hasattr(os, 'WNOHANG')):
1531 return
1532 elif not has_subprocess_support:
1533 return
1534
1535 # Reap all our dead child processes so we don't leave zombies around.
1536 # These hog resources and might be causing some of the buildbots to die.
1537 while True:
1538 try:
1539 # Read the exit status of any child process which already completed
1540 pid, status = os.waitpid(-1, os.WNOHANG)
1541 except OSError:
1542 break
1543
1544 if pid == 0:
1545 break
1546
1547 print_warning(f"reap_children() reaped child process {pid}")
1548 environment_altered = True
1549
1550
1551@contextlib.contextmanager

Callers 15

tearDownMethod · 0.90
tearDownModuleFunction · 0.90
setUpMethod · 0.90
tearDownMethod · 0.90
setUpMethod · 0.90
tearDownMethod · 0.90
setUpMethod · 0.90
tearDownMethod · 0.90
setUpMethod · 0.90
tearDownMethod · 0.90
setUpMethod · 0.90
tearDownMethod · 0.90

Calls 1

print_warningFunction · 0.70

Tested by 15

tearDownMethod · 0.72
tearDownModuleFunction · 0.72
setUpMethod · 0.72
tearDownMethod · 0.72
setUpMethod · 0.72
tearDownMethod · 0.72
setUpMethod · 0.72
tearDownMethod · 0.72
setUpMethod · 0.72
tearDownMethod · 0.72
setUpMethod · 0.72
tearDownMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…