From 819f967844b441d272d9e139ec05f0028ed9bb31 Mon Sep 17 00:00:00 2001 From: claude Date: Mon, 20 Jul 2026 19:40:56 +0000 Subject: [PATCH] fix(lint): resolve pylint findings in gateway_init - Extract _sigkill_all() to cut nesting depth below the 5-block limit - Add pylint: disable=consider-using-with on Popen (process must outlive caller) - Break long SIGHUP signal line to stay within 100 chars --- bot_bottle/gateway_init.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bot_bottle/gateway_init.py b/bot_bottle/gateway_init.py index 799428e..4b25bdc 100644 --- a/bot_bottle/gateway_init.py +++ b/bot_bottle/gateway_init.py @@ -150,7 +150,7 @@ def _pump(name: str, stream: IO[bytes]) -> None: def _spawn(spec: _DaemonSpec) -> subprocess.Popen[bytes]: env = _env_for_daemon(spec.name, dict(os.environ)) - proc = subprocess.Popen( + proc = subprocess.Popen( # pylint: disable=consider-using-with _argv_for_daemon(spec.name, spec.argv, env), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -197,6 +197,14 @@ class _Supervisor: except ProcessLookupError: pass + def _sigkill_all(self) -> None: + for _, p in self.procs: + if p.poll() is None: + try: + p.kill() + except ProcessLookupError: + pass + def request_restart(self, daemon_name: str) -> bool: """Queue a daemon restart for the main loop to process. @@ -249,12 +257,7 @@ class _Supervisor: f"grace ({_GRACE_SECONDS:.0f}s) elapsed; SIGKILL on " f"{', '.join(still_running)}" ) - for _, p in self.procs: - if p.poll() is None: - try: - p.kill() - except ProcessLookupError: - pass + self._sigkill_all() done = all(p.poll() is not None for _, p in self.procs) if done: @@ -375,7 +378,9 @@ def main(argv: Sequence[str] | None = None) -> int: # --signal HUP ` after writing routes.yaml. The kernel # delivers SIGHUP to PID 1 (this supervisor); forward it to # mitmdump so it reloads its addon. - signal.signal(signal.SIGHUP, lambda *_: sup.forward_signal(signal.SIGHUP, "egress")) # type: ignore + signal.signal( # type: ignore + signal.SIGHUP, lambda *_: sup.forward_signal(signal.SIGHUP, "egress") + ) while not sup.tick(): time.sleep(_POLL_INTERVAL)