summaryrefslogtreecommitdiff
path: root/git/cmd.py
diff options
context:
space:
mode:
authorOswin Nathanial <oswin.x.nathanial@sonymobile.com>2015-10-09 15:22:28 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2015-10-09 15:25:30 +0900
commit7cc0e6caa3117f694d367d3f3b80db1e365aac94 (patch)
tree09494ddd8aa4525e03b05d41fc0ec62e18ded715 /git/cmd.py
parent9e1c90eb69e2dfd5fdf8418caa695112bd285f21 (diff)
downloadgitpython-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.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/git/cmd.py b/git/cmd.py
index fd3e815b..392f3a0b 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -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]