Commit 828ce738 authored by Victor Stinner's avatar Victor Stinner

Issue #12363: improve siginterrupt() tests

Add a basic synchronization code between the child and the parent processes:
the child writes "ready" to stdout.
parent 7af070fc
...@@ -333,6 +333,9 @@ class SiginterruptTest(unittest.TestCase): ...@@ -333,6 +333,9 @@ class SiginterruptTest(unittest.TestCase):
def handler(signum, frame): def handler(signum, frame):
pass pass
print("ready")
sys.stdout.flush()
signal.signal(signal.SIGALRM, handler) signal.signal(signal.SIGALRM, handler)
if interrupt is not None: if interrupt is not None:
signal.siginterrupt(signal.SIGALRM, interrupt) signal.siginterrupt(signal.SIGALRM, interrupt)
...@@ -353,11 +356,15 @@ class SiginterruptTest(unittest.TestCase): ...@@ -353,11 +356,15 @@ class SiginterruptTest(unittest.TestCase):
""" % (interrupt,) """ % (interrupt,)
with spawn_python('-c', code) as process: with spawn_python('-c', code) as process:
try: try:
# wait until the child process is loaded and has started
first_line = process.stdout.readline()
stdout, stderr = process.communicate(timeout=3.0) stdout, stderr = process.communicate(timeout=3.0)
except subprocess.TimeoutExpired: except subprocess.TimeoutExpired:
process.kill() process.kill()
return False return False
else: else:
stdout = first_line + stdout
exitcode = process.wait() exitcode = process.wait()
if exitcode not in (2, 3): if exitcode not in (2, 3):
raise Exception("Child error (exit code %s): %s" raise Exception("Child error (exit code %s): %s"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment