fork download
  1. import time
  2. import asyncio
  3. from threading import Thread
  4.  
  5.  
  6. async def f():
  7. for i in range(4, 0, -1):
  8. print(i)
  9. await asyncio.sleep(1)
  10. else:
  11. print('DONE')
  12.  
  13.  
  14.  
  15. def async_from_sync(coro):
  16. def do_async():
  17. async def inner():
  18. await asyncio.create_task(coro())
  19. asyncio.run(inner())
  20. t = Thread(target=do_async)
  21. t.start()
  22.  
  23.  
  24. def main():
  25. async_from_sync(f)
  26. time.sleep(6) # че-то делаем
  27.  
  28.  
  29. main()
Success #stdin #stdout 0.11s 16584KB
stdin
Standard input is empty
stdout
4
3
2
1
DONE