summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2012-05-08 00:51:34 -0700
committerSebastian Thiel <byronimo@gmail.com>2012-05-08 00:51:34 -0700
commit95878d20f264eb10d09796e595e9a1d811e92e84 (patch)
tree38a09919773bfc17c86e222a9bf16d2d17dee416
parent6e86f8a8a0638abe2c18ae0bb36cc992b0ababe5 (diff)
parentf467834059bb1297df97df4e03149cd2b48b81e3 (diff)
downloadgitpython-95878d20f264eb10d09796e595e9a1d811e92e84.tar.gz
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.
-rw-r--r--git/cmd.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 576a5300..0cd3e86c 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -73,6 +73,9 @@ class Git(LazyMixin):
self.args = args
def __del__(self):
+ self.proc.stdout.close()
+ self.proc.stderr.close()
+
# did the process finish already so we have a return code ?
if self.proc.poll() is not None:
return
@@ -84,6 +87,8 @@ class Git(LazyMixin):
# try to kill it
try:
os.kill(self.proc.pid, 2) # interrupt signal
+ except OSError:
+ pass # ignore error when process already died
except AttributeError:
# try windows
# for some reason, providing None for stdout/stderr still prints something. This is why
@@ -100,6 +105,8 @@ class Git(LazyMixin):
:raise GitCommandError: if the return status is not 0"""
status = self.proc.wait()
+ self.proc.stdout.close()
+ self.proc.stderr.close()
if status != 0:
raise GitCommandError(self.args, status, self.proc.stderr.read())
# END status handling