Skip to content

Commit a75b275

Browse files
authored
Merge pull request #112 from nathanchance/avoid-ruff-plw1509
boot-qemu.py: Workaround PLW1509 warning from Ruff
2 parents ef9fa5a + 4bc7264 commit a75b275

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

boot-qemu.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,17 @@ def _run_gdb(self):
212212
utils.die('Port 1234 is already in use, is QEMU running?')
213213

214214
utils.green('Starting QEMU with gdb connection on port 1234...')
215-
with subprocess.Popen(qemu_cmd,
216-
preexec_fn=os.setpgrp) as qemu_proc:
215+
# setpgrp() is equivalent to setpgid(0, 0). The 'process_group'
216+
# keyword argument is equivalent to calling setpgid(0, arg) but it
217+
# is only available in Python 3.11 and newer.
218+
if sys.version_info >= (3, 11, 0):
219+
popen_kwargs = {'process_group': 0}
220+
else:
221+
popen_kwargs = {'preexec_fn': os.setpgrp}
222+
# pylint seems to think process_group will be used with Python 3.10
223+
# and earlier?
224+
# pylint: disable-next=unexpected-keyword-arg
225+
with subprocess.Popen(qemu_cmd, **popen_kwargs) as qemu_proc:
217226
utils.green(f"Starting {self.gdb_bin}...")
218227
with subprocess.Popen(gdb_cmd) as gdb_proc, \
219228
contextlib.suppress(KeyboardInterrupt):

0 commit comments

Comments
 (0)