diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-01-07 20:00:06 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-01-07 20:00:21 +0100 |
commit | 36cdfd3209909163549850709d7f12fdf1316434 (patch) | |
tree | 4aa624df4eb2b345e594764139fa264a486e437d /git/cmd.py | |
parent | f4a49ff2dddc66bbe25af554caba2351fbf21702 (diff) | |
download | gitpython-36cdfd3209909163549850709d7f12fdf1316434.tar.gz |
Made improvements to assure test-cases don't leak file handles
At least leakage is considerably reduced.
Additionally, a test-case was added which triggers failure if auto-disposal
of resources wouldn't work.
Fixes #60
Diffstat (limited to 'git/cmd.py')
-rw-r--r-- | git/cmd.py | 22 |
1 files changed, 16 insertions, 6 deletions
@@ -38,6 +38,9 @@ log = logging.getLogger('git.cmd') __all__ = ('Git', ) +if sys.platform != 'win32': + WindowsError = OSError + # ============================================================================== ## @name Utilities @@ -203,11 +206,18 @@ class Git(LazyMixin): self.args = args def __del__(self): - self.proc.stdout.close() - self.proc.stderr.close() + if self.proc is None: + return + + proc = self.proc + self.proc = None + if proc.stdin: + proc.stdin.close() + proc.stdout.close() + proc.stderr.close() # did the process finish already so we have a return code ? - if self.proc.poll() is not None: + if proc.poll() is not None: return # can be that nothing really exists anymore ... @@ -216,8 +226,8 @@ class Git(LazyMixin): # try to kill it try: - os.kill(self.proc.pid, 2) # interrupt signal - self.proc.wait() # ensure process goes away + os.kill(proc.pid, 2) # interrupt signal + proc.wait() # ensure process goes away except (OSError, WindowsError): pass # ignore error when process already died except AttributeError: @@ -225,7 +235,7 @@ class Git(LazyMixin): # for some reason, providing None for stdout/stderr still prints something. This is why # we simply use the shell and redirect to nul. Its slower than CreateProcess, question # is whether we really want to see all these messages. Its annoying no matter what. - call(("TASKKILL /F /T /PID %s 2>nul 1>nul" % str(self.proc.pid)), shell=True) + call(("TASKKILL /F /T /PID %s 2>nul 1>nul" % str(proc.pid)), shell=True) # END exception handling def __getattr__(self, attr): |