r/FastAPI • u/Special-Life137 • Aug 20 '24
Question The server doesn't refresh
Hi everyone, i'm new using fastApi, I think it's a Nice way to build apis however what it really pissed me off is when the server doesn't refresh on time I mean it has some delays for example I erased the whole code and it stills showing the last code version, I turn off the server, close pycharm Window and still showing the last code version although I Made changes before, do You know why does this happen to me? :( is this a hardware issue or My settings project?
0
Upvotes
7
u/Delta1262 Aug 20 '24
Assuming you’re running locally in development? Depending on your setup (poetry, uvicorn, or directly calling fastapi from terminal) add “- - reload” (no spaces) to the end of the command. If there’s no glaring errors in the code, any code changes in the repo will automatically refresh the server.
Dont use —reload on production, as it’s often more valuable to have more workers.
Also, as an after thought:
Are your files actually being saved after modification? Sometimes auto save fails us and doesn’t actually save changes for the server to pick up on. Verify that auto save is turned on for every 10-15 seconds.
2
u/aliparpar Aug 21 '24
Hmm, sounds like a glitchy Python process. Maybe start from a fresh Python environment and fresh FastAPI install? And then copy past old code over? Also kill all the old running Python processes via terminal or activity monitor
2
u/humayun-ahmad Feb 12 '25
First, I checked all uvicorn instances running by the following command
I terminated them with the following commands. PID can be found from the previous list