https://i.sstatic.net/FcuEc4Vo.png
I am using FastAPI, and I frequently encounter an issue where the WatchFiles tool gets stuck during the reload process when I press Ctrl+S to save changes. This situation causes the terminal to freeze, making it impossible to exit or perform any further actions. The only solution is to forcefully close the terminal.
However, after closing the terminal, the port previously used by the FastAPI application remains occupied, and when I try to run the application on the same port, it still shows the old version of the application. This forces me to run the application on a different port each time, which is not practical and becomes quite hectic.
Here are the steps I follow and the issues I face:
Save changes using Ctrl+S.
WatchFiles sometimes gets stuck on reloading.
Terminal freezes, requiring a forceful close.
The old port remains occupied, showing the old version of the application.
The port appears in netstat, but the PID is not findable in Windows Task Manager.
Question:
How can I prevent WatchFiles from getting stuck on reload?
If it does get stuck, what is the proper way to release the old port without having to change ports each time?
Any help or suggestions on how to resolve this issue would be greatly appreciated.
What I Have Tried:
I tried looking for the PID of the process using netstat and attempted to kill it via the command line, but the PID does not appear in Windows Task Manager.
I attempted restarting my development environment and even my computer, but the problem persists.
I searched for solutions online but have not found any effective method to prevent WatchFiles from getting stuck or to release the old port easily.
What I Expected:
I expected WatchFiles to reload the application smoothly without freezing.
If the process gets stuck, I expected to be able to easily release the occupied port and rerun the application on the same port without showing the old version.
Pratik Kharche is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.