Skip to content

Commit 936124f

Browse files
authored
Merge pull request #1980 from apache/juerg/preexec
casdprocessmanager.py: Don't use `preexec_fn` on Python 3.11+
2 parents 504e442 + 797c827 commit 936124f

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/buildstream/_cas/casdprocessmanager.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import shutil
2121
import stat
2222
import subprocess
23+
import sys
2324
import tempfile
2425
import time
2526
from subprocess import CalledProcessError
@@ -126,16 +127,21 @@ def __init__(
126127
self._start_time = time.time()
127128
self._logfile = self._rotate_and_get_next_logfile()
128129

130+
# Create a new process group for buildbox-casd such that SIGINT won't reach it.
131+
if sys.version_info >= (3, 11):
132+
process_group_kwargs = {"process_group": 0}
133+
else:
134+
process_group_kwargs = {"preexec_fn": os.setpgrp}
135+
129136
with open(self._logfile, "w", encoding="utf-8") as logfile_fp:
130137
# The frontend will take care of terminating buildbox-casd.
131-
# Create a new process group for it such that SIGINT won't reach it.
132-
self.process = subprocess.Popen( # pylint: disable=consider-using-with, subprocess-popen-preexec-fn
138+
self.process = subprocess.Popen( # pylint: disable=consider-using-with
133139
casd_args,
134140
cwd=path,
135141
stdout=logfile_fp,
136142
stderr=subprocess.STDOUT,
137-
preexec_fn=os.setpgrp,
138143
env=self.__buildbox_casd_env(),
144+
**process_group_kwargs
139145
)
140146

141147
self._casd_channel = None

0 commit comments

Comments
 (0)