This is an automated email from the ASF dual-hosted git repository.

juergbi pushed a commit to branch juerg/preexec
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit cecb0285b4f64de7906784bc7d25a0f66b8f0f30
Author: Jürg Billeter <[email protected]>
AuthorDate: Fri Dec 20 16:49:00 2024 +0100

    casdprocessmanager.py: Don't use `preexec_fn` on Python 3.11+
    
    The use of `preexec_fn` is not generally safe when using multiple
    threads.
---
 src/buildstream/_cas/casdprocessmanager.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/buildstream/_cas/casdprocessmanager.py 
b/src/buildstream/_cas/casdprocessmanager.py
index 5cc64853e..d1157dd93 100644
--- a/src/buildstream/_cas/casdprocessmanager.py
+++ b/src/buildstream/_cas/casdprocessmanager.py
@@ -20,6 +20,7 @@ import random
 import shutil
 import stat
 import subprocess
+import sys
 import tempfile
 import time
 from subprocess import CalledProcessError
@@ -126,16 +127,21 @@ class CASDProcessManager:
         self._start_time = time.time()
         self._logfile = self._rotate_and_get_next_logfile()
 
+        # Create a new process group for buildbox-casd such that SIGINT won't 
reach it.
+        if sys.version_info >= (3, 11):
+            process_group_kwargs = {"process_group": 0}
+        else:
+            process_group_kwargs = {"preexec_fn": os.setpgrp}
+
         with open(self._logfile, "w", encoding="utf-8") as logfile_fp:
             # The frontend will take care of terminating buildbox-casd.
-            # Create a new process group for it such that SIGINT won't reach 
it.
-            self.process = subprocess.Popen(  # pylint: 
disable=consider-using-with, subprocess-popen-preexec-fn
+            self.process = subprocess.Popen(  # pylint: 
disable=consider-using-with
                 casd_args,
                 cwd=path,
                 stdout=logfile_fp,
                 stderr=subprocess.STDOUT,
-                preexec_fn=os.setpgrp,
                 env=self.__buildbox_casd_env(),
+                **process_group_kwargs
             )
 
         self._casd_channel = None

Reply via email to