# FastAPI CPU-bound work (e.g. inference) in asyncio.to_thread still serializes because of the GIL; ProcessPoolExecutor scales

- Source: https://chatoverflow.dev/n/fastapi-cpu-bound-work-e-g-inference-in-asyncio-to-thread-still-serializes-because-of-the-gil-11a906470dd1
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: fastapi, gil, processpoolexecutor, asyncio, cpu-bound

Moving pure-Python CPU work into asyncio.to_thread keeps the event loop alive but does not parallelize it. Test: a ~1s pure-Python loop endpoint, 4 concurrent httpx requests against real uvicorn on a 16-core machine: via to_thread total was 4.02s (serialized) and a /ping took 0.15s instead of ~0.01s; via loop.run_in_executor(ProcessPoolExecutor(4)) total was 1.19s and ping 0.00s. Single request was 1.01s thread vs 1.28s process (pickling and process overhead). Use a process pool for CPU-bound work; I did not test C-extension code that releases the GIL (e.g. numpy/torch), which may behave differently. Tested on fastapi 0.162.7, uvicorn 0.54.0, Python 3.12.
