]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-119273: Don't run test_ioctl in a process group (#119275)
authorVictor Stinner <vstinner@python.org>
Wed, 29 May 2024 12:44:09 +0000 (14:44 +0200)
committerGitHub <noreply@github.com>
Wed, 29 May 2024 12:44:09 +0000 (12:44 +0000)
Python test runner no longer runs tests using TTY (ex: test_ioctl) in
a process group (using setsid()). Previously, tests using TTY were
skipped.

Lib/test/libregrtest/run_workers.py
Lib/test/libregrtest/worker.py
Misc/NEWS.d/next/Tests/2024-05-20-18-06-31.gh-issue-119273.hf-yhX.rst [new file with mode: 0644]

index 235047cf2e563caa06492b2b74157575e56355aa..a71050e66db3bd7a56172d668092cee5daae755f 100644 (file)
@@ -142,14 +142,20 @@ class WorkerThread(threading.Thread):
             return
         self._killed = True
 
-        if USE_PROCESS_GROUP:
+        use_killpg = USE_PROCESS_GROUP
+        if use_killpg:
+            parent_sid = os.getsid(0)
+            sid = os.getsid(popen.pid)
+            use_killpg = (sid != parent_sid)
+
+        if use_killpg:
             what = f"{self} process group"
         else:
             what = f"{self} process"
 
         print(f"Kill {what}", file=sys.stderr, flush=True)
         try:
-            if USE_PROCESS_GROUP:
+            if use_killpg:
                 os.killpg(popen.pid, signal.SIGKILL)
             else:
                 popen.kill()
index f8b8e45eca327682d877c9292bbf377c8a6cfab2..15d32b5baa04d09c8a7cb6ad46dda252ae334bcc 100644 (file)
@@ -14,6 +14,9 @@ from .utils import (
 
 
 USE_PROCESS_GROUP = (hasattr(os, "setsid") and hasattr(os, "killpg"))
+NEED_TTY = set('''
+    test_ioctl
+'''.split())
 
 
 def create_worker_process(runtests: WorkerRunTests, output_fd: int,
@@ -47,7 +50,10 @@ def create_worker_process(runtests: WorkerRunTests, output_fd: int,
         close_fds=True,
         cwd=work_dir,
     )
-    if USE_PROCESS_GROUP:
+
+    # Don't use setsid() in tests using TTY
+    test_name = runtests.tests[0]
+    if USE_PROCESS_GROUP and test_name not in NEED_TTY:
         kwargs['start_new_session'] = True
 
     # Pass json_file to the worker process
diff --git a/Misc/NEWS.d/next/Tests/2024-05-20-18-06-31.gh-issue-119273.hf-yhX.rst b/Misc/NEWS.d/next/Tests/2024-05-20-18-06-31.gh-issue-119273.hf-yhX.rst
new file mode 100644 (file)
index 0000000..905b4e3
--- /dev/null
@@ -0,0 +1,3 @@
+Python test runner no longer runs tests using TTY (ex: test_ioctl) in a
+process group (using ``setsid()``). Previously, tests using TTY were
+skipped. Patch by Victor Stinner.