This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
Neels Hofmeyr gerrit-no-reply at lists.osmocom.orgNeels Hofmeyr has submitted this change and it was merged.
Change subject: osmoutil: end_proc: wait for term in a loop
......................................................................
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
---
M osmopy/osmoutil.py
1 file 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 @@
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()
--
To view, visit https://gerrit.osmocom.org/1936
To unsubscribe, visit https://gerrit.osmocom.org/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I98849e4550116c5666fdf6f5d4cbb576ffa3e14a
Gerrit-PatchSet: 2
Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Neels Hofmeyr <nhofmeyr at sysmocom.de>