I'm trying to run several functions at the same time (approximately or course) with different parameters and repeat that at the start of every minute.
I managed to get an asyncio
example to run where I get a function callback
to run at specific times with a different parameter, but what I can't figure out is how to run it (and keep running it forever) at very specific times (i.e. I want to run it at the start of every minute, so at 19:00:00, 19:01:00, etc..).
Asyncio call_at
should be able to do that, but it uses a time format that is not the standard python time format and I can't figure out to specify that time format as the 00 seconds of the next minute.
import asyncio
import time
def callback(n, loop, msg):
print(msg)
print('callback {} invoked at {}'.format(n, loop.time()))
async def main(loop):
now = loop.time()
print('clock time: {}'.format(time.time()))
print('loop time: {}'.format(now))
print('registering callbacks')
loop.call_at(now + 0.2, callback, 1, loop, 'a')
loop.call_at(now + 0.1, callback, 2, loop, 'b')
loop.call_soon(callback, 3, loop, 'c')
await asyncio.sleep(1)
event_loop = asyncio.get_event_loop()
try:
print('entering event loop')
event_loop.run_until_complete(main(event_loop))
finally:
print('closing event loop')
event_loop.close()