Sync over async (ARCH2023)
Key python.async.sync-over-async · Severity error · Category async
Blocking on an asynchronous operation from a synchronous context risks deadlocks and thread-pool starvation, and defeats the purpose of async. Keeping the call chain async all the way down is the correct fix.
Incorrect
Section titled “Incorrect”import asyncio
def get_user(user_id): return asyncio.run(fetch_user(user_id)) # blocking in sync contextCorrect
Section titled “Correct”async def get_user(user_id): return await fetch_user(user_id)Make the caller async and await the result; do not force synchronous bridges.