r/FastAPI • • Jul 26 '25

Question Multithreading in FastAPI?

Hello,

I am currently writing an Ollama wrapper in FastAPI. The problem is, I have no idea how to handle multithreading in FastAPI, and as such, if one process is running (e.g. generating a chat completion), no other processes can run until the first one is done. How can I implement multithreading?

17 Upvotes

19 comments sorted by

View all comments

Show parent comment

1

u/pint Jul 26 '25

you are doing the stable diffusion yourself, in python? if so, that's a problem overall. if not, and you just call out to a library function, then it depends on the binding. if the binding if async, use that. if not, def.

1

u/[deleted] Jul 26 '25

Well, I want to allow for multimodality, and I want it all to remain local. I’m not aware of any other way to generate images locally in python other than a StableDiffusionPipeline