Aller au contenu

Sync over async (ARCH2023)

Ce contenu n’est pas encore disponible dans votre langue.

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.

import asyncio
def get_user(user_id):
return asyncio.run(fetch_user(user_id)) # blocking in sync context
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.