_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

Async/Await v Pythonu

21. 06. 2025 1 min read intermediate

Async Python je ideální pro I/O-bound operace — HTTP requesty, databáze, file I/O. Jedna thread, tisíce concurrent operací.

Basics asyncio

import asyncio async def fetch_data(url: str) -> dict: async with aiohttp.ClientSession() as session: async with session.get(url) as response: return await response.json() async def main():

Concurrent requests

urls = [“https://api.example.com/1”, “https://api.example.com/2”] results = await asyncio.gather(*[fetch_data(u) for u in urls]) return results asyncio.run(main())

When to Use async

  • HTTP requesty (aiohttp, httpx)
  • Database queries (asyncpg, databases)
  • File I/O
  • WebSocket servery
  • NE pro CPU-bound operace (použijte multiprocessing)

Key Takeaway

Async pro I/O-bound, multiprocessing pro CPU-bound. asyncio.gather pro concurrent operace.

pythonasyncasyncio
Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.