From ed6e24b176c25bdff363bd409fe3160b47b3202a Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 4 Aug 2023 14:32:48 +1000 Subject: [PATCH] Fix resource leak in git_log utility module Resolve a resource leak I encountered in credits_git_gen.py during development, where it could exit with an OSError: "Too many open files". --- tools/utils/git_log.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/utils/git_log.py b/tools/utils/git_log.py index 98c046aead7..f5bcd86b33d 100644 --- a/tools/utils/git_log.py +++ b/tools/utils/git_log.py @@ -55,11 +55,11 @@ class GitCommit: ) + args # print(" ".join(cmd)) - p = subprocess.Popen( + with subprocess.Popen( cmd, stdout=subprocess.PIPE, - ) - return p.stdout.read() + ) as p: + return p.stdout.read() @property def sha1_short(self): @@ -71,11 +71,11 @@ class GitCommit: "--short", self.sha1, ) - p = subprocess.Popen( + with subprocess.Popen( cmd, stdout=subprocess.PIPE, - ) - return p.stdout.read().strip().decode('ascii') + ) as p: + return p.stdout.read().strip().decode('ascii') @property def author(self):