I ran into an asyncIO problem. I want to have my program do something while a task a coroutine is being run, and after the coroutine is done, exit.
I've simplified my problem into this snippet:
import time
import asyncio
async def long_task():
time.sleep(3)
return "DONE !"
def do_while_idle():
loop = asyncio.get_event_loop()
task = loop.create_task(long_task)
while not task.done():
time.sleep(1)
print("IDLE")
print(task.result())
do_while_idle()
I'd like to have this output:
IDLE
IDLE
IDLE
DONE !
Thanks in advance.