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 shutil import stat import subprocess +import sys import tempfile import time from subprocess import CalledProcessError @@ -126,16 +127,21 @@ def __init__( 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