diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2012-05-08 00:51:34 -0700 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2012-05-08 00:51:34 -0700 |
commit | 95878d20f264eb10d09796e595e9a1d811e92e84 (patch) | |
tree | 38a09919773bfc17c86e222a9bf16d2d17dee416 | |
parent | 6e86f8a8a0638abe2c18ae0bb36cc992b0ababe5 (diff) | |
parent | f467834059bb1297df97df4e03149cd2b48b81e3 (diff) | |
download | gitpython-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.py | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -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 |