python fastapi 默认线程数
python fastapi 默认线程数
默认的线程数限制:
asyncio
事件循环的默认线程池执行器(ThreadPoolExecutor
) 默认是:
max_workers = min(32, (os.cpu_count() or 1) + 4)
fastapi 修改线程数
同步函数的线程池大小:可以通过 anyio.to_thread.current_default_thread_limiter().total_tokens
获取。默认是40个。
修改线程池大小:
from anyio import to_thread
async def foo():
# Set the maximum number of worker threads to 60
to_thread.current_default_thread_limiter().total_tokens = 60