Skip to content

Commit

Permalink
boot-qemu.py: Workaround PLW1509 warning from Ruff
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nathanchance committed Aug 18, 2023
1 parent ef9fa5a commit 4bc7264
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions boot-qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,17 @@ def _run_gdb(self):
utils.die('Port 1234 is already in use, is QEMU running?')

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

0 comments on commit 4bc7264

Please sign in to comment.