Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fastapi dev runs stuck #11573

Open
1 task done
kingcwt opened this issue May 13, 2024 · 13 comments
Open
1 task done

fastapi dev runs stuck #11573

kingcwt opened this issue May 13, 2024 · 13 comments

Comments

@kingcwt
Copy link

kingcwt commented May 13, 2024

Privileged issue

  • I'm @tiangolo or he asked me directly to create an issue here.

Issue Content

The first time I ran fastapi dev, there was no problem, but I encountered a code error. Then after I modified the code and saved it, a WARNING: WatchFiles detected changes in 'tool/index.py'. Reloading... then got stuck and could not exit.

image
@ankit-brijwasi
Copy link

Any updates on this @kingcwt? facing the same issue!

@3to1null
Copy link

Could be related to: encode/uvicorn#2000

@Omachonu-prosper
Copy link

I currently have a slightly different issue from yours @kingcwt but it's still an issue with fastapi cli (dev and run)
The Code
image

The Error
image
image

@AIdjis
Copy link

AIdjis commented May 28, 2024

do not use the fastapi dev to run your application just use uvicorn instead, i do not face any issue with uvicorn

@ceb10n
Copy link
Contributor

ceb10n commented Jun 5, 2024

I tryied to reproduce it, but without success.

But sometimes I get the same problem running uvicorn with --reload in cmder/windows. I think it is related to uvicorn instead of fastapi

@RasmusN
Copy link

RasmusN commented Jul 9, 2024

I'm having the same issue here on windows 10.
I think this is related: https://www.reddit.com/r/FastAPI/comments/13oynf6/keeps_old_routes_after_changing_cache_problem/

It is like fastapi keeps an old version of the code cached somewhere. Even if I force kill fastpi and restart it, it loads an old version of my code.

It works (for a while) if I change port.

edit: this seems to be a uvicorn open issue which in turn is caused by a bug in cpython (open issue)

@Sarmad426
Copy link

I think uvicorn dev server is better as of now. As we are not getting any updates about the Fast API cli. Its important to note that this may be fixed in near future. It happens a lot with Fast API server. So you have to kill the terminal and open a new one to re-run the project. Its painful.

@arslanahmad768
Copy link

@Sarmad426 Yes, you are right i am also facing the same issue I tried with both the commands such as
fast API dev filename
or
if name == "main":
uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
Sometimes it stuck you have to forcefully close the server but still, the port is running on the cache. So you have to run the server again on a different port.

@thecouchcoder
Copy link

thecouchcoder commented Aug 27, 2024

Running into a similar issue. I can I kill the the process with ctrl+c, but I cannot run on the same port. Attempting to run on the same port prints out the message like everything is working fine, but trying to access /docs spins forever. Switching to a new port works fine.

  • Windows PowerShell (occurs both from Windows Terminal and PyCharm Terminal)
  • Python 3.12
  • Fast API 0.112.2

@WilliamStam
Copy link

in pycharm if you use the "run" method to run the project then it tends to hand after reloading. if you task manager kill python it reloads again. something definately fishy there.

if you just do uvicorn --reload in terminal it tends to work better but still a massive PITA on windows :( easier to just not run it with reload

win11, py3.12, pycharm

@rutexd
Copy link

rutexd commented Sep 2, 2024

can confirm. win 11.
issue present at least month.

WARNING: WatchFiles detected changes in 'config.py'. Reloading... and its stuck.
Its works fine until certain moment but hard to debug when exactly. after kill and start new it can stuck again.

No pycharm, vscode + .venv, server started by hand in terminal (❯ fastapi dev webserver.py --port 8080)

UPDATE:

do not use the fastapi dev to run your application just use uvicorn instead, i do not face any issue with uvicorn

relating to the comments, this doesnt look to help aswell.
image

@mattmess1221
Copy link

I wonder if this would still happen with uvicorn's --timeout-graceful-shutdown option. Using fastapi dev, you have to set it using an environment variable UVICORN_TIMEOUT_GRACEFUL_SHUTDOWN=5.

@atomicjarrod
Copy link

I have been getting this same problem whether uvicorn main:app --reload or fastapi dev method launching from powershell. (no pycharm here)

  • Win11.
  • VSCode
  • Python 3.12.6
  • FastAPI 0.115.0
  • Uvicorn 0.31.0

Resorting to Task Manager (Ctrl+Shift+Esc) and killing python tasks as Ctrl+C often won't quit server and closing powershell window and launching another doesn't seem to kill it either.

Installed fastapi using "fastapi[standard]" and also removed and tried just installing separately fastapi and uvicorn
Based on this thread #2000 just to test tried downgrading just uvicorn to 0.22 with no difference then to 0.21 (0.21.1) and sure enough it stops being stuck and reloads in a second?

WARNING:  StatReload detected changes in 'api.py'. Reloading...
INFO:     Started server process [9192]
INFO:     Waiting for application startup.
INFO:     Application startup complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests