Added intervalexec.py
This commit is contained in:
parent
b93c2f71d4
commit
f529e8bcd3
26
intervalexec.py
Normal file
26
intervalexec.py
Normal file
@ -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:])
|
Loading…
Reference in New Issue
Block a user