Skip to content

Commit 4bc7264

Browse files
committed
boot-qemu.py: Workaround PLW1509 warning from Ruff
This is the same warning from pylint that was disabled in ClangBuiltLinux/actions-workflows#5. boot-qemu.py:216:35: PLW1509 `preexec_fn` argument is unsafe when using threads 'preexec_fn' is on the path towards deprecation, so workaround this warning by refactoring the code to use the new keyword argument 'process_group' when using Python 3.11 and newer, which makes it clear that we don't need 'preexec_fn' longterm. This conveniently hides the 'preexec_fn' use in Popen() so there is no more warning. Link: https://beta.ruff.rs/docs/rules/subprocess-popen-preexec-fn/ Signed-off-by: Nathan Chancellor <nathan@kernel.org>
1 parent ef9fa5a commit 4bc7264

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)