Unverified Commit 8ad6ff00 authored by Mark McLoughlin's avatar Mark McLoughlin Committed by GitHub
Browse files

[Test] Fix @create_new_process_for_each_test("fork") in interactive shell pipeline (#29130)


Signed-off-by: default avatarMark McLoughlin <markmc@redhat.com>
parent f2145efc
...@@ -1261,9 +1261,6 @@ def fork_new_process_for_each_test(func: Callable[_P, None]) -> Callable[_P, Non ...@@ -1261,9 +1261,6 @@ def fork_new_process_for_each_test(func: Callable[_P, None]) -> Callable[_P, Non
@functools.wraps(func) @functools.wraps(func)
def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> None: def wrapper(*args: _P.args, **kwargs: _P.kwargs) -> None:
# Make the process the leader of its own process group
# to avoid sending SIGTERM to the parent process
os.setpgrp()
from _pytest.outcomes import Skipped from _pytest.outcomes import Skipped
# Create a unique temporary file to store exception info from child # Create a unique temporary file to store exception info from child
...@@ -1283,6 +1280,9 @@ def fork_new_process_for_each_test(func: Callable[_P, None]) -> Callable[_P, Non ...@@ -1283,6 +1280,9 @@ def fork_new_process_for_each_test(func: Callable[_P, None]) -> Callable[_P, Non
pid = os.fork() pid = os.fork()
print(f"Fork a new process to run a test {pid}") print(f"Fork a new process to run a test {pid}")
if pid == 0: if pid == 0:
# Make the child process the leader of its own process group
# to avoid sending SIGTERM to the parent process
os.setpgrp()
# Parent process responsible for deleting, don't delete # Parent process responsible for deleting, don't delete
# in child. # in child.
delete_after.pop_all() delete_after.pop_all()
...@@ -1322,14 +1322,12 @@ def fork_new_process_for_each_test(func: Callable[_P, None]) -> Callable[_P, Non ...@@ -1322,14 +1322,12 @@ def fork_new_process_for_each_test(func: Callable[_P, None]) -> Callable[_P, Non
else: else:
os._exit(0) os._exit(0)
else: else:
pgid = os.getpgid(pid) # After setpgrp(), the child's pgid equals its pid
pgid = pid
_pid, _exitcode = os.waitpid(pid, 0) _pid, _exitcode = os.waitpid(pid, 0)
# ignore SIGTERM signal itself # kill all child processes - but they may already have exited cleanly
old_signal_handler = signal.signal(signal.SIGTERM, signal.SIG_IGN) with contextlib.suppress(ProcessLookupError):
# kill all child processes
os.killpg(pgid, signal.SIGTERM) os.killpg(pgid, signal.SIGTERM)
# restore the signal handler
signal.signal(signal.SIGTERM, old_signal_handler)
if _exitcode != 0: if _exitcode != 0:
# Try to read the exception from the child process # Try to read the exception from the child process
exc_info = {} exc_info = {}
......
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