The nature of Async
The nature of Async is an Event Loop.
The result is a coroutine object after invoke a async
function. The function can only be executed after becoming a task.
Basic 1
import asyncio
import time
async def say_after(delay, what):
await asyncio.sleep(delay)
return f"{what} - {delay}"
async def main():
print(f"started at {time.strftime('%X')}")
await say_after(1, "hello")
await say_after(2, "world")
print(f"finished at {time.strftime('%X')}")
asyncio.run(main())
July 10, 2024Less than 1 minute