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