| 1 | n/a | import signal, subprocess, sys, time |
|---|
| 2 | n/a | # On Linux this causes os.waitpid to fail with OSError as the OS has already |
|---|
| 3 | n/a | # reaped our child process. The wait() passing the OSError on to the caller |
|---|
| 4 | n/a | # and causing us to exit with an error is what we are testing against. |
|---|
| 5 | n/a | signal.signal(signal.SIGCHLD, signal.SIG_IGN) |
|---|
| 6 | n/a | subprocess.Popen([sys.executable, '-c', 'print("albatross")']).wait() |
|---|
| 7 | n/a | # Also ensure poll() handles an errno.ECHILD appropriately. |
|---|
| 8 | n/a | p = subprocess.Popen([sys.executable, '-c', 'print("albatross")']) |
|---|
| 9 | n/a | num_polls = 0 |
|---|
| 10 | n/a | while p.poll() is None: |
|---|
| 11 | n/a | # Waiting for the process to finish. |
|---|
| 12 | n/a | time.sleep(0.01) # Avoid being a CPU busy loop. |
|---|
| 13 | n/a | num_polls += 1 |
|---|
| 14 | n/a | if num_polls > 3000: |
|---|
| 15 | n/a | raise RuntimeError('poll should have returned 0 within 30 seconds') |
|---|