From 4207aef0292dbd9c988167efcc43111cebc6ce83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 1 Oct 2024 19:30:34 +0200 Subject: [PATCH] don't leak memory in global table unless we want to record performance --- pkgs/clan-cli/clan_cli/cmd.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkgs/clan-cli/clan_cli/cmd.py b/pkgs/clan-cli/clan_cli/cmd.py index 001623ca7..e489a89e0 100644 --- a/pkgs/clan-cli/clan_cli/cmd.py +++ b/pkgs/clan-cli/clan_cli/cmd.py @@ -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( @@ -135,7 +135,8 @@ def run( process.wait() tend = datetime.datetime.now(tz=datetime.UTC) - global TIME_TABLE + global TIME_TABLE + if TIME_TABLE: TIME_TABLE.add(shlex.join(cmd), tend - tstart) # Wait for the subprocess to finish