SKY-Q401 · Quality, structure and performance
Async blocking call
A blocking call, such as requests.get(), time.sleep() or subprocess.run(), made directly inside an async def. An async server runs many requests on one thread, and a blocking call holds that thread until it returns.
- Languages
- Python
- Quality gate
- counted toward the gate limits (full and diff scans)
- Finding type
- defect
Why it matters
While one request waits five seconds for a slow rates API, every other request on that event loop waits too, including health checks. Under load the service looks hung and gets restarted, although nothing crashed.
What Skylos flags
"""Exchange-rate endpoint.""" import requestsfrom fastapi import FastAPI app = FastAPI()RATES_URL = "https://rates.example.com" @app.get("/rates/{currency}")async def get_rate(currency: str): url = f"{RATES_URL}/{currency}" response = requests.get(url, timeout=5) return response.json()What Skylos leaves alone
"""Exchange-rate endpoint.""" import asyncio import requestsfrom fastapi import FastAPI app = FastAPI()RATES_URL = "https://rates.example.com" @app.get("/rates/{currency}")async def get_rate(currency: str): url = f"{RATES_URL}/{currency}" response = await asyncio.to_thread(requests.get, url, timeout=5) return response.json()Why Skylos leaves it alone
requests.get is not called on the event loop here: it is handed to asyncio.to_thread(), which runs it on a worker thread while the loop keeps serving other requests.
How Skylos decides
- Runs with
--qualityon Python files. Looks at calls whose innermost enclosing function is anasync def; a call inside a nesteddeforlambdais not counted, since that code may run elsewhere. - Reports a call to
time.sleep,requests.get,post,put,delete,patch,headorrequest,urllib.request.urlopen,subprocess.run,call,check_outputorcheck_call, oros.system. - Resolves
import x as yandfrom x import faliases in the file, sofrom time import sleepfollowed bysleep(1)is found. A name writtenmodule.funcis matched even without an import. - Reports HIGH on the line of the call; the message names the async replacement.
How to fix it
Use an async HTTP client and await it. (For a call that has no async version, await asyncio.to_thread(...) as in the example above.)
"""Exchange-rate endpoint.""" Removed: import requestsAdded: import httpxfrom fastapi import FastAPI app = FastAPI()RATES_URL = "https://rates.example.com" @app.get("/rates/{currency}")async def get_rate(currency: str): url = f"{RATES_URL}/{currency}"Removed: response = requests.get(url, timeout=5)Added: async with httpx.AsyncClient(timeout=5) as client:Added: response = await client.get(url) return response.json()When it can be wrong
- A blocking call in an async command-line script that does nothing else at the same time is reported, although nobody waits on the loop.
- It misses
urllib.request.urlopen()written with its full module path,requests.Session().get(), blocking database drivers and file reads, which are not on the list.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the line of the call.
Python time.sleep(0.1) # skylos: ignore[SKY-Q401] startup only, before serving[tool.skylos] ignore = ["SKY-Q401"]turns the rule off for the project.