Merge pull request 'fix resource leaks' (#2191) from fix-warning into main

This commit is contained in:
clan-bot
2024-10-01 18:03:58 +00:00
2 changed files with 14 additions and 12 deletions

View File

@@ -71,8 +71,6 @@ class TimeTable:
weakref.finalize(self, self.table_print)
def table_print(self) -> None:
if os.getenv("PERF") != "1":
return
print("======== CMD TIMETABLE ========")
# Sort the table by time in descending order
@@ -96,7 +94,9 @@ class TimeTable:
self.table[cmd] = time
TIME_TABLE = TimeTable()
TIME_TABLE = None
if os.environ.get("CLAN_CLI_PERF"):
TIME_TABLE = TimeTable()
def run(
@@ -120,23 +120,24 @@ 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)
if TIME_TABLE:
TIME_TABLE.add(shlex.join(cmd), tend - tstart)
# Wait for the subprocess to finish
cmd_out = CmdOut(

View File

@@ -36,6 +36,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"