fix file descriptor leak in cmd.run()

we were leaking pipes.
This commit is contained in:
Jörg Thalheim
2024-10-01 19:25:16 +02:00
parent 237327ead3
commit d5d6774124
2 changed files with 11 additions and 10 deletions

View File

@@ -120,23 +120,23 @@ def run(
tstart = datetime.datetime.now(tz=datetime.UTC) tstart = datetime.datetime.now(tz=datetime.UTC)
# Start the subprocess # Start the subprocess
process = subprocess.Popen( with subprocess.Popen(
cmd, cmd,
cwd=str(cwd), cwd=str(cwd),
env=env, env=env,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
) ) as process:
stdout_buf, stderr_buf = handle_output(process, log) stdout_buf, stderr_buf = handle_output(process, log)
if input: if input:
process.communicate(input) process.communicate(input)
else: else:
process.wait() process.wait()
tend = datetime.datetime.now(tz=datetime.UTC) tend = datetime.datetime.now(tz=datetime.UTC)
global TIME_TABLE global TIME_TABLE
TIME_TABLE.add(shlex.join(cmd), tend - tstart) TIME_TABLE.add(shlex.join(cmd), tend - tstart)
# Wait for the subprocess to finish # Wait for the subprocess to finish
cmd_out = CmdOut( cmd_out = CmdOut(

View File

@@ -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 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" norecursedirs = "tests/helpers"
markers = ["impure", "with_core"] markers = ["impure", "with_core"]
filterwarnings = "default::ResourceWarning"
[tool.mypy] [tool.mypy]
python_version = "3.12" python_version = "3.12"