diff options
author | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2017-02-27 02:38:42 +0100 |
---|---|---|
committer | Neels Hofmeyr <nhofmeyr@sysmocom.de> | 2017-03-06 15:31:08 +0100 |
commit | 9b0a51fb8761f448d6ab604eb7f39bf197c5b59d (patch) | |
tree | 57d4cd0371acb97742e84e90cd4f9c61c662a30c | |
parent | 119bed52fa77294ad810dc9cc29dcdb933b89c3f (diff) |
osmoutil: end_proc: wait for term in a loop
Recent commit b59b677c9b13483aac72b15f4f797863d841d958 called proc.terminate()
instead of killing right away, with a .1 second sleep. Reduce this sleep to
a minuscule first wait_time, remaining tolerant for processes that take longer.
Actually all of our current processes are very fast to terminate. This patch
was created while looking for a different problem, now that it's there we might
as well keep it.
Change-Id: I98849e4550116c5666fdf6f5d4cbb576ffa3e14a
-rwxr-xr-x | osmopy/osmoutil.py | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/osmopy/osmoutil.py b/osmopy/osmoutil.py index 87203d5..8f0369b 100755 --- a/osmopy/osmoutil.py +++ b/osmopy/osmoutil.py @@ -47,13 +47,27 @@ def end_proc(proc): return proc.terminate() - time.sleep(.1) - rc = proc.poll() - if rc is not None: - print "Terminated child process" - else: + time_to_wait_for_term = 5 + wait_step = 0.001 + waited_time = 0 + while True: + # poll returns None if proc is still running + rc = proc.poll() + if rc is not None: + break + waited_time += wait_step + # make wait_step approach 1.0 + wait_step = (1. + 5. * wait_step) / 6. + if waited_time >= time_to_wait_for_term: + break + time.sleep(wait_step) + + if proc.poll() is None: + # termination seems to be slower than that, let's just kill proc.kill() print "Killed child process" + elif waited_time > .002: + print "Terminating took %.3fs" % waited_time proc.wait() |