import asyncio import time async def busy_task(): i = 0 while i < 100: i += 1 await asyncio.sleep(3.0) return 1 async def main(): tasks = [asyncio.create_task(busy_task()) for i in range(5)] start_time = time.time() try: # this is to prevent waiting in 'select' all day, # which makes the python intepreter not respond to # mini-scalene / SCALENE while True: if time.time() - start_time > 4.0: break # print(asyncio.all_tasks()) await asyncio.sleep(0) # yield except KeyboardInterrupt: pass finally: print("Done.") asyncio.run(main())