summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-01-21 17:00:03 +0200
committerLars Wirzenius <liw@liw.fi>2018-01-21 17:00:03 +0200
commit431d4ae1b32d08f25c22d2864f0682b5df64080f (patch)
tree6cfc45a273d9f8e6affea8bc8c72aa9cbb0803c1
parentb6e368fa57b0d6be32bc8a52c409d033f7b36170 (diff)
parent4299e0691a55566865b0e8a9745ee94327c78bca (diff)
downloadcliapp-431d4ae1b32d08f25c22d2864f0682b5df64080f.tar.gz
Merge branch 'master' of git://git.liw.fi/cliapp
-rw-r--r--NEWS4
-rw-r--r--cliapp/runcmd.py13
-rw-r--r--without-tests1
3 files changed, 14 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 07ab93c..e76e659 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,10 @@ NEWS for cliapp
Version 1.20170827+git, not yet released
----------------------------------------
+* The `runcmd` timeout behaviour has changed a little. Previously, a
+ timeout meant the command would be terminated. Termination is now
+ optional: if the `timeout_callback` function returns a true value,
+ termination happens. Otherwise not.
Version 1.20170827, released 2017-08-27
----------------------------------------
diff --git a/cliapp/runcmd.py b/cliapp/runcmd.py
index 7123fed..818bafd 100644
--- a/cliapp/runcmd.py
+++ b/cliapp/runcmd.py
@@ -174,6 +174,7 @@ def _run_pipeline(procs, feed_stdin, pipe_stdin, pipe_stdout, pipe_stderr,
pos = 0
io_size = 1024
latest_output = time.time()
+ timeout_quit = False
timeout = False
def set_nonblocking(fd):
@@ -200,7 +201,7 @@ def _run_pipeline(procs, feed_stdin, pipe_stdin, pipe_stdout, pipe_stderr,
return True # pragma: no cover
return False
- while not timeout and still_running():
+ while not timeout_quit and still_running():
rlist = []
if not stdout_eof and pipe_stdout == subprocess.PIPE:
rlist.append(procs[-1].stdout)
@@ -255,14 +256,18 @@ def _run_pipeline(procs, feed_stdin, pipe_stdin, pipe_stdout, pipe_stderr,
stderr_eof = True
timeout = False
+ if timeout and timeout_callback: # pragma: no cover
+ result = timeout_callback()
+ if result:
+ timeout_quit = True
+ elif timeout: # pragma: no cover
+ timeout_quit = True
+
while not timeout and still_running():
for p in procs:
if p.returncode is None:
p.wait()
- if timeout and timeout_callback: # pragma: no cover
- timeout_callback()
-
errorcodes = [p.returncode for p in procs if p.returncode != 0] or [0]
# Ensure that the pipeline doesn't leak file descriptors
diff --git a/without-tests b/without-tests
index d7d5704..b381a46 100644
--- a/without-tests
+++ b/without-tests
@@ -12,4 +12,5 @@
./test-plugins/aaa_hello_plugin.py
example4.py
example5.py
+example6.py
example_runcmd.py