diff options
author | Oswin Nathanial <oswin.x.nathanial@sonymobile.com> | 2015-10-09 15:22:28 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2015-10-09 15:25:30 +0900 |
commit | 7cc0e6caa3117f694d367d3f3b80db1e365aac94 (patch) | |
tree | 09494ddd8aa4525e03b05d41fc0ec62e18ded715 /git/cmd.py | |
parent | 9e1c90eb69e2dfd5fdf8418caa695112bd285f21 (diff) | |
download | gitpython-7cc0e6caa3117f694d367d3f3b80db1e365aac94.tar.gz |
Only create watchdog and event if timeout is specified in execute command
If the timeout is not specified, we don't need the overhead of
creating a watchdog and event.
Change-Id: I53ff891af24d4c27fb16bf4bb35910dd1d19d238
Diffstat (limited to 'git/cmd.py')
-rw-r--r-- | git/cmd.py | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -602,8 +602,6 @@ class Git(LazyMixin): if as_process: return self.AutoInterrupt(proc, command) - kill_check = threading.Event() - def _kill_process(pid): """ Callback method to kill a process. """ p = Popen(['ps', '--ppid', str(pid)], stdout=PIPE) @@ -625,7 +623,9 @@ class Git(LazyMixin): return # end - watchdog = threading.Timer(timeout, _kill_process, args=(proc.pid, )) + if timeout: + kill_check = threading.Event() + watchdog = threading.Timer(timeout, _kill_process, args=(proc.pid, )) # Wait for the process to return status = 0 @@ -633,12 +633,14 @@ class Git(LazyMixin): stderr_value = b'' try: if output_stream is None: - watchdog.start() + if timeout: + watchdog.start() stdout_value, stderr_value = proc.communicate() - watchdog.cancel() - if kill_check.isSet(): - stderr_value = 'Timeout: the command "%s" did not complete in %d ' \ - 'secs.' % (" ".join(command), timeout) + if timeout: + watchdog.cancel() + if kill_check.isSet(): + stderr_value = 'Timeout: the command "%s" did not complete in %d ' \ + 'secs.' % (" ".join(command), timeout) # strip trailing "\n" if stdout_value.endswith(b"\n"): stdout_value = stdout_value[:-1] |