Merge pull request 'fix resource leaks' (#2191) from fix-warning into main
This commit is contained in:
@@ -71,8 +71,6 @@ class TimeTable:
|
|||||||
weakref.finalize(self, self.table_print)
|
weakref.finalize(self, self.table_print)
|
||||||
|
|
||||||
def table_print(self) -> None:
|
def table_print(self) -> None:
|
||||||
if os.getenv("PERF") != "1":
|
|
||||||
return
|
|
||||||
print("======== CMD TIMETABLE ========")
|
print("======== CMD TIMETABLE ========")
|
||||||
|
|
||||||
# Sort the table by time in descending order
|
# Sort the table by time in descending order
|
||||||
@@ -96,7 +94,9 @@ class TimeTable:
|
|||||||
self.table[cmd] = time
|
self.table[cmd] = time
|
||||||
|
|
||||||
|
|
||||||
TIME_TABLE = TimeTable()
|
TIME_TABLE = None
|
||||||
|
if os.environ.get("CLAN_CLI_PERF"):
|
||||||
|
TIME_TABLE = TimeTable()
|
||||||
|
|
||||||
|
|
||||||
def run(
|
def run(
|
||||||
@@ -120,23 +120,24 @@ 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)
|
if TIME_TABLE:
|
||||||
|
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(
|
||||||
|
|||||||
@@ -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
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user