From d5d677412480751d75f968ce689a830f8068d0c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 1 Oct 2024 19:25:16 +0200 Subject: [PATCH] fix file descriptor leak in cmd.run() we were leaking pipes. --- pkgs/clan-cli/clan_cli/cmd.py | 20 ++++++++++---------- pkgs/clan-cli/pyproject.toml | 1 + 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/cmd.py b/pkgs/clan-cli/clan_cli/cmd.py index a17842c99..001623ca7 100644 --- a/pkgs/clan-cli/clan_cli/cmd.py +++ b/pkgs/clan-cli/clan_cli/cmd.py @@ -120,23 +120,23 @@ def run( tstart = datetime.datetime.now(tz=datetime.UTC) # Start the subprocess - process = subprocess.Popen( + with subprocess.Popen( cmd, cwd=str(cwd), env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - ) - stdout_buf, stderr_buf = handle_output(process, log) + ) as process: + stdout_buf, stderr_buf = handle_output(process, log) - if input: - process.communicate(input) - else: - process.wait() - tend = datetime.datetime.now(tz=datetime.UTC) + if input: + process.communicate(input) + else: + process.wait() + tend = datetime.datetime.now(tz=datetime.UTC) - global TIME_TABLE - TIME_TABLE.add(shlex.join(cmd), tend - tstart) + global TIME_TABLE + TIME_TABLE.add(shlex.join(cmd), tend - tstart) # Wait for the subprocess to finish cmd_out = CmdOut( diff --git a/pkgs/clan-cli/pyproject.toml b/pkgs/clan-cli/pyproject.toml index 32990eb95..9f97d9d0a 100644 --- a/pkgs/clan-cli/pyproject.toml +++ b/pkgs/clan-cli/pyproject.toml @@ -35,6 +35,7 @@ log_format = "%(levelname)s: %(message)s\n %(pathname)s:%(lineno)d::%(func addopts = "--cov . --cov-report term --cov-report html:.reports/html --no-cov-on-fail --durations 5 --color=yes --new-first -n auto" # Add --pdb for debugging norecursedirs = "tests/helpers" markers = ["impure", "with_core"] +filterwarnings = "default::ResourceWarning" [tool.mypy] python_version = "3.12"