advisory-circular/intervalexec.py

26 lines
480 B
Python
Raw Normal View History

2020-05-03 23:44:50 +00:00
#!/usr/bin/env python3
2019-12-19 00:51:52 +00:00
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:])