Agents/test_loop.py

41 lines
882 B
Python

import time
def ping():
print("Ping alle 30 Sekunden")
def ping1():
print("Ping1 alle 30 Sekunden")
def ping2():
print("Ping2 alle 60 Sekunden")
def ping3():
print("Ping3 alle 3600 Sekunden")
def main_loop():
tasks = [
{"interval": 3, "last_run": time.time(), "functions": [ping, ping1]},
{"interval": 6, "last_run": time.time(), "functions": [ping2]},
{"interval": 36, "last_run": time.time(), "functions": [ping3]}
]
while True:
current_time = time.time()
for task in tasks:
if current_time - task["last_run"] >= task["interval"]:
for function in task["functions"]:
function()
task["last_run"] = current_time
# Eine kurze Pause, um die CPU nicht zu überlasten
time.sleep(1)
if __name__ == "__main__":
main_loop()