[PATCH] python/osmo-python-tests[master]: osmoutil: end_proc: wait for term in a loop

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Tue Feb 28 02:10:50 UTC 2017


Review at  https://gerrit.osmocom.org/1936

osmoutil: end_proc: wait for term in a loop

Allows a minuscule first wait_time, and is tolerant for processes that take
longer to terminate.

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
---
M osmopy/osmoutil.py
1 file changed, 19 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/36/1936/1

diff --git a/osmopy/osmoutil.py b/osmopy/osmoutil.py
index faedc43..8f0369b 100755
--- a/osmopy/osmoutil.py
+++ b/osmopy/osmoutil.py
@@ -47,12 +47,27 @@
         return
 
     proc.terminate()
-    time.sleep(.01)
-    rc = proc.poll()
-    if rc is None:
+    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
-        print "Killed child process"
         proc.kill()
+        print "Killed child process"
+    elif waited_time > .002:
+        print "Terminating took %.3fs" % waited_time
     proc.wait()
 
 

-- 
To view, visit https://gerrit.osmocom.org/1936
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I98849e4550116c5666fdf6f5d4cbb576ffa3e14a
Gerrit-PatchSet: 1
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>


More information about the gerrit-log mailing list