Skip to content

Commit 95878d2

Browse files
committedMay 8, 2012
Merge pull request #58 from sugi/cmd-fd-leak-fix
Fixes on cmd.py (fd leak and signal exception) Currently if command is called with as_proces=True, pipes for the command will not be closed. cb68f36 makes sure to close command file descriptors. Ignore signal exception on AutoInterrupt destructor. When command run as subprocess, AutoInterrupt will kill the process on destructor. However, if process already finished, it raise OSError exception.
2 parents 6e86f8a + f467834 commit 95878d2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed
 

‎git/cmd.py

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def __init__(self, proc, args ):
7373
self.args = args
7474

7575
def __del__(self):
76+
self.proc.stdout.close()
77+
self.proc.stderr.close()
78+
7679
# did the process finish already so we have a return code ?
7780
if self.proc.poll() is not None:
7881
return
@@ -84,6 +87,8 @@ def __del__(self):
8487
# try to kill it
8588
try:
8689
os.kill(self.proc.pid, 2) # interrupt signal
90+
except OSError:
91+
pass # ignore error when process already died
8792
except AttributeError:
8893
# try windows
8994
# for some reason, providing None for stdout/stderr still prints something. This is why
@@ -100,6 +105,8 @@ def wait(self):
100105
101106
:raise GitCommandError: if the return status is not 0"""
102107
status = self.proc.wait()
108+
self.proc.stdout.close()
109+
self.proc.stderr.close()
103110
if status != 0:
104111
raise GitCommandError(self.args, status, self.proc.stderr.read())
105112
# END status handling

0 commit comments

Comments
 (0)
Failed to load comments.