I have a program like this
task_2_running = False
async def task2():
task_2_running = True
await do_something()
task_2_running = False
async def main():
while True:
x = await task1()
do_something(x)
if some_condition(x) and not task_2_running:
#Do task2() but don't wait until it finished
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
How do I call task2() so the loop will continue without waiting for task2() to finish, and task2() will still finish sometime in the future?