Skip to content

Commit

Permalink
Merge pull request #1980 from apache/juerg/preexec
Browse files Browse the repository at this point in the history
casdprocessmanager.py: Don't use `preexec_fn` on Python 3.11+
  • Loading branch information
juergbi authored Jan 18, 2025
2 parents 504e442 + 797c827 commit 936124f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/buildstream/_cas/casdprocessmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import shutil
import stat
import subprocess
import sys
import tempfile
import time
from subprocess import CalledProcessError
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 936124f

Please sign in to comment.