Skip to content

Commit

Permalink
pythongh-109582: test_fork_signal_handling should wait for event (pyt…
Browse files Browse the repository at this point in the history
…hon#109605)

Sometimes the child_handled event was missing because either
the child quits before it gets a chance to handle the signal,
or the parent asserts before the event notification is
delivered via IPC.  Synchronize explicitly to avoid this.
  • Loading branch information
sorcio authored Sep 21, 2023
1 parent 2aceb21 commit 608c1f3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Lib/test/test_asyncio/test_unix_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import stat
import sys
import threading
import time
import unittest
from unittest import mock
import warnings
from test import support
from test.support import os_helper
from test.support import socket_helper
from test.support import wait_process
Expand Down Expand Up @@ -1911,8 +1913,14 @@ def test_fork_signal_handling(self):
parent_handled = manager.Event()

def child_main():
signal.signal(signal.SIGTERM, lambda *args: child_handled.set())
def on_sigterm(*args):
child_handled.set()
sys.exit()

signal.signal(signal.SIGTERM, on_sigterm)
child_started.set()
while True:
time.sleep(1)

async def main():
loop = asyncio.get_running_loop()
Expand All @@ -1922,7 +1930,7 @@ async def main():
process.start()
child_started.wait()
os.kill(process.pid, signal.SIGTERM)
process.join()
process.join(timeout=support.SHORT_TIMEOUT)

async def func():
await asyncio.sleep(0.1)
Expand All @@ -1933,6 +1941,7 @@ async def func():

asyncio.run(main())

child_handled.wait(timeout=support.SHORT_TIMEOUT)
self.assertFalse(parent_handled.is_set())
self.assertTrue(child_handled.is_set())

Expand Down

0 comments on commit 608c1f3

Please sign in to comment.