Async Python Programming
asyncio enables concurrent code execution for I/O-bound tasks.
Basic async/await
import asyncio
async def fetch_data(url):
await asyncio.sleep(1) # Simulate API call
return f"Data from {url}"
async def main():
results = await asyncio.gather(
fetch_data("url1"),
fetch_data("url2"),
)
print(results)
asyncio.run(main())
Discussion 0
No comments yet. Be the first to start the discussion!
Leave a Comment