From 797c827d455b97710048aad2084fd2957396beef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Billeter?= Date: Fri, 20 Dec 2024 16:49:00 +0100 Subject: [PATCH] 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 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