You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ju...@apache.org on 2024/12/20 15:53:49 UTC

(buildstream) branch juerg/preexec created (now 6bb61630c)

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

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


      at 6bb61630c casdprocessmanager.py: Don't use `preexec_fn` on Python 3.11+

This branch includes the following new commits:

     new 9364c439b Use subprocess umask support
     new 6bb61630c casdprocessmanager.py: Don't use `preexec_fn` on Python 3.11+

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(buildstream) 02/02: casdprocessmanager.py: Don't use `preexec_fn` on Python 3.11+

Posted by ju...@apache.org.
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 6bb61630c95a5c82f3aa31f440ebed85bc462cd5
Author: Jürg Billeter <j...@bitron.ch>
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


(buildstream) 01/02: Use subprocess umask support

Posted by ju...@apache.org.
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 9364c439be93026017e81563a43387fe6c52d4aa
Author: Seppo Yli-Olli <se...@gmail.com>
AuthorDate: Fri Sep 16 20:39:05 2022 +0300

    Use subprocess umask support
    
    This requires Python 3.9 or newer
---
 src/buildstream/utils.py | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/src/buildstream/utils.py b/src/buildstream/utils.py
index 9d058a28e..572ba26f4 100644
--- a/src/buildstream/utils.py
+++ b/src/buildstream/utils.py
@@ -1260,14 +1260,7 @@ def _call(*popenargs, terminate=False, **kwargs):
 
     process = None
 
-    old_preexec_fn = kwargs.get("preexec_fn")
-    if "preexec_fn" in kwargs:
-        del kwargs["preexec_fn"]
-
-    def preexec_fn():
-        os.umask(stat.S_IWGRP | stat.S_IWOTH)
-        if old_preexec_fn is not None:
-            old_preexec_fn()
+    kwargs["umask"] = stat.S_IWGRP | stat.S_IWOTH
 
     # Handle termination, suspend and resume
     def kill_proc():
@@ -1313,7 +1306,7 @@ def _call(*popenargs, terminate=False, **kwargs):
             os.killpg(group_id, signal.SIGCONT)
 
     with _signals.suspendable(suspend_proc, resume_proc), _signals.terminator(kill_proc), subprocess.Popen(
-        *popenargs, preexec_fn=preexec_fn, universal_newlines=True, **kwargs
+        *popenargs, universal_newlines=True, **kwargs
     ) as process:
         # Here, we don't use `process.communicate()` directly without a timeout
         # This is because, if we were to do that, and the process would never