asyncio
noun
say it: “AY-sink-eye-oh” /ˈeɪsɪŋkˌaɪˌoʊ/
Python's standard module for running async code, with tools such as asyncio.run, asyncio.gather and asyncio.sleep.
What is asyncio?
asyncio is the standard module that runs async code. Its best trick is doing many slow waits at the same time instead of one after another.
import asyncio
async def fetch(city):
await asyncio.sleep(1)
return city
async def main():
results = await asyncio.gather(fetch("Paris"), fetch("Tokyo"))
print(results) # both done in about 1 second, not 2
asyncio.run(main())
In a sentence
- “asyncio.gather waited on three services at once.”
- “The script starts its async code with asyncio.run(main()).”
Level: Freelancer · More Python terms at this level
Updated