Skip to content

Include 'timeout' parameter in Git execute #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 16, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename execute param 'timeout' to 'kill_after_timeout'
Change-Id: I8ab3d5affb3f040dd9630687fb20aedbd7510070
  • Loading branch information
OswinNathanial authored and dpursehouse committed Oct 13, 2015
commit 4faf5cd43dcd0b3eea0a3e71077c21f4d029eb99
20 changes: 10 additions & 10 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

execute_kwargs = ('istream', 'with_keep_cwd', 'with_extended_output',
'with_exceptions', 'as_process', 'stdout_as_string',
'output_stream', 'with_stdout', 'timeout')
'output_stream', 'with_stdout', 'kill_after_timeout')

log = logging.getLogger('git.cmd')
log.addHandler(logging.NullHandler())
Expand Down Expand Up @@ -476,7 +476,7 @@ def execute(self, command,
as_process=False,
output_stream=None,
stdout_as_string=True,
timeout=None,
kill_after_timeout=None,
with_stdout=True,
**subprocess_kwargs
):
Expand Down Expand Up @@ -533,7 +533,7 @@ def execute(self, command,

:param with_stdout: If True, default True, we open stdout on the created process

:param timeout:
:param kill_after_timeout:
To specify a timeout in seconds for the git command, after which the process
should be killed. This will have no effect if as_process is set to True. It is
set to None by default and will let the process run until the timeout is
Expand Down Expand Up @@ -576,8 +576,8 @@ def execute(self, command,

if sys.platform == 'win32':
cmd_not_found_exception = WindowsError
if timeout:
raise GitCommandError('"timeout" feature is not supported on Windows.')
if kill_after_timeout:
raise GitCommandError('"kill_after_timeout" feature is not supported on Windows.')
else:
if sys.version_info[0] > 2:
cmd_not_found_exception = FileNotFoundError # NOQA # this is defined, but flake8 doesn't know
Expand Down Expand Up @@ -623,24 +623,24 @@ def _kill_process(pid):
return
# end

if timeout:
if kill_after_timeout:
kill_check = threading.Event()
watchdog = threading.Timer(timeout, _kill_process, args=(proc.pid, ))
watchdog = threading.Timer(kill_after_timeout, _kill_process, args=(proc.pid, ))

# Wait for the process to return
status = 0
stdout_value = b''
stderr_value = b''
try:
if output_stream is None:
if timeout:
if kill_after_timeout:
watchdog.start()
stdout_value, stderr_value = proc.communicate()
if timeout:
if kill_after_timeout:
watchdog.cancel()
if kill_check.isSet():
stderr_value = 'Timeout: the command "%s" did not complete in %d ' \
'secs.' % (" ".join(command), timeout)
'secs.' % (" ".join(command), kill_after_timeout)
# strip trailing "\n"
if stdout_value.endswith(b"\n"):
stdout_value = stdout_value[:-1]
Expand Down