Blocking call in async (ARCH2028)
Esta página aún no está disponible en tu idioma.
Key python.async.blocking-call-in-async · Severity error · Category async
Synchronous blocking calls (time.sleep, blocking IO, sync HTTP/DB drivers) inside an async function stall the event loop and starve all concurrency. Use the asynchronous equivalents instead.
Incorrect
Section titled “Incorrect”import time
async def poll(): time.sleep(5) # blocks the event loop return await fetch_status()Correct
Section titled “Correct”import asyncio
async def poll(): await asyncio.sleep(5) # does not block the loop return await fetch_status()Replace the blocking call with its async equivalent, or offload it to a thread pool via run_in_executor.