Slightly reduce run_tests.py CPU usage.

The watch_kill_switch loop was pretty busy, adding a simple
timeout reduces CPU consumption.

The CPU consumption of run_tests.py is still higher than I'd expect
to just update a terminal, but I don't know where to investigate
further.
This commit is contained in:
Thomas Sewell 2016-10-19 11:26:44 +11:00
parent 3b679b0ce3
commit 68e22b2d14
1 changed files with 2 additions and 0 deletions

View File

@ -221,6 +221,7 @@ def run_test(test, status_queue, kill_switch, verbose=False, stuck_timeout=None,
# Poll the kill switch.
def watch_kill_switch():
while True:
interval = 1.0
if test_status[0] is not RUNNING:
break
if kill_switch.wait(1):
@ -228,6 +229,7 @@ def run_test(test, status_queue, kill_switch, verbose=False, stuck_timeout=None,
break
test_status[0] = CANCELLED
kill_family(grace_period, process.pid)
time.sleep(interval)
kill_switch_thread = threading.Thread(target=watch_kill_switch)
kill_switch_thread.daemon = True
kill_switch_thread.start()