17db96d56Sopenharmony_ciimport signal, subprocess, sys, time
27db96d56Sopenharmony_ci# On Linux this causes os.waitpid to fail with OSError as the OS has already
37db96d56Sopenharmony_ci# reaped our child process.  The wait() passing the OSError on to the caller
47db96d56Sopenharmony_ci# and causing us to exit with an error is what we are testing against.
57db96d56Sopenharmony_cisignal.signal(signal.SIGCHLD, signal.SIG_IGN)
67db96d56Sopenharmony_cisubprocess.Popen([sys.executable, '-c', 'print("albatross")']).wait()
77db96d56Sopenharmony_ci# Also ensure poll() handles an errno.ECHILD appropriately.
87db96d56Sopenharmony_cip = subprocess.Popen([sys.executable, '-c', 'print("albatross")'])
97db96d56Sopenharmony_cinum_polls = 0
107db96d56Sopenharmony_ciwhile p.poll() is None:
117db96d56Sopenharmony_ci    # Waiting for the process to finish.
127db96d56Sopenharmony_ci    time.sleep(0.01)  # Avoid being a CPU busy loop.
137db96d56Sopenharmony_ci    num_polls += 1
147db96d56Sopenharmony_ci    if num_polls > 3000:
157db96d56Sopenharmony_ci        raise RuntimeError('poll should have returned 0 within 30 seconds')
16