From 7cc0e6caa3117f694d367d3f3b80db1e365aac94 Mon Sep 17 00:00:00 2001 From: Oswin Nathanial Date: Fri, 9 Oct 2015 15:22:28 +0900 Subject: 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 --- git/cmd.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'git/cmd.py') 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] -- cgit v1.2.1