[Python] Threading in FastAPI [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 10, 2025.

  1. Stack

    Stack Membro Participativo

    Kind of new to fastapi, I have a local toy fastapi app with an endpoint that will read in around 500-1000 (which might go up in the future) json data (each around 5-10kb) from local files. Given its I/O intensive nature, I am trying to use threads/threadpool in my endpoint to see if there is any improvement in loading speed, instead of sequentially read.

    So under the context of fastapi, should I use the old fashion ThreadPoolExecutor within my endpoint, or use asyncio.get_running_loop(). From my research, looks like asyncio.get_running_loop() suits I/O bound task in fast api better, and ThreadPoolExecutor seems have more boilerplate.

    Any hint is appreciated.

    Continue reading...

Compartilhe esta Página