From f529e8bcd3760f5c46c06bf8a838eff364a7495a Mon Sep 17 00:00:00 2001 From: John Wiseman Date: Wed, 18 Dec 2019 16:51:52 -0800 Subject: [PATCH] Added intervalexec.py --- intervalexec.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 intervalexec.py diff --git a/intervalexec.py b/intervalexec.py new file mode 100644 index 0000000..adb4727 --- /dev/null +++ b/intervalexec.py @@ -0,0 +1,26 @@ +import subprocess +import sys +import time + + + +def run(args): + subprocess.run(args, check=True) + + +def main(args): + interval_secs = float(args[0]) + exec_args = args[1:] + while True: + start_time = time.time() + next_time = start_time + interval_secs + run(exec_args) + now = time.time() + delay = next_time - now + if delay > 0.01: + time.sleep(delay) + + + +if __name__ == '__main__': + main(sys.argv[1:])