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.
()
| 1519 | environment_altered = False |
| 1520 | |
| 1521 | def 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 |
searching dependent graphs…