Closed TahaAhvazi closed 5 months ago
Exactly I have been experiencing this since whenever I restart my FastAPI application, it doesnt restart gracefully but logs this exact message like yours
I need a computer with Windows.
Am having the same error and am using Windows
Exactly I have been experiencing this since whenever I restart my FastAPI application, it doesnt restart gracefully but logs this exact message like yours
Yes exactly, and its just appears in the latest version of uvicorn I donwgraded mmy uvicorn version to 0.27.1 and its totally fine
Just started learning and experimenting since yesterday using FastAPI for the first time. I have same problem.
Every Ctrl+S or any file save in the repo (folder being watched for changes) reloads the app with no problem, but the terminal is cluttered with this exception every single time.
Btw the reload of app is being done on file save even when there were no changes the file (which I didnt experience with saving a file without changes in Angular app for example)
Just started learning and experimenting since yesterday using FastAPI for the first time. I have same problem.
Every Ctrl+S or any file save in the repo (folder being watched for changes) reloads the app with no problem, but the terminal is cluttered with this exception every single time.
Btw the reload of app is being done on file save even when there were no changes the file (which I didnt experience with saving a file without changes in Angular app for example)
Hi, i had the same problem. for now,you can use the previous version of uvicorn and solve the problem you can use version : 0.27.1
Just to add my me too here, me too. Windows machine, PyEnv en Poetry, tried 3 python versions 3.9/3.11/3.12 all same issue. Rolling back to uvicorn 0.27.1 fixed the issue with --reload
+1
Maybe a clue is that when I run it in command it behaves better than running it in powershell.
The error occurs only in 0.29.0
, but 0.28.1
just works fine.
Note that this isn't an error per-se. This is a traceback from the updated shutdown procedure which propagates the killing signal if one occurred (as happens automatically for reloading, or on pressing [Ctrl]+[C], etc.). It is not an error in the application or server.
Still it seems sensible to suppress this in situations in which the propagation is expected. That should be when the server is not run programmatically, i.e. via Server.run
inside main
.
Since the goal is just to suppress the traceback on graceful shutdown (i.e. KeyboardInterrupt
) it should be sufficient to catch Turns out this happens deeply inside multiprocessing. I've addressed this in #2317.KeyboardInterrupt
, disable sys.excepthook
, and then re-raise the exception.
Can someone check whether #2317 fixes this issues on Windows? I was only able to test this on MacOS and Linux.
@maxfischer2781 I've run both 0.29.0 and https://github.com/maxfischer2781/uvicorn/tree/suppress-signal-traceback via poetry and your basic test.py.
Result is your fix works fine on this sample (first output below) and the 0.29.0 fails.
Jhn in F:\_test_projects\uvicorn λ poetry update uvicorn
Updating dependencies
Resolving dependencies... (16.3s)
Package operations: 0 installs, 1 update, 0 removals
- Updating uvicorn (0.29.0 -> 0.29.0 cf88d65)
Writing lock file
Jhn in F:\_test_projects\uvicorn λ poetry run python -m uvicorn test:dummy_app --reload
INFO: Will watch for changes in these directories: ['F:\\_test_projects\\uvicorn']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [57072] using StatReload
INFO: Started server process [61392]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [61392]
INFO: Stopping reloader process [57072]
Jhn in F:\_test_projects\uvicorn λ poetry update uvicorn
Updating dependencies
Resolving dependencies... (0.1s)
Package operations: 0 installs, 1 update, 0 removals
- Updating uvicorn (0.29.0 cf88d65 -> 0.29.0)
Writing lock file
Jhn in F:\_test_projects\uvicorn λ poetry run python -m uvicorn test:dummy_app --reload
INFO: Will watch for changes in these directories: ['F:\\_test_projects\\uvicorn']
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [54420] using StatReload
INFO: Started server process [44236]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Shutting down
INFO: Waiting for application shutdown.
INFO: Application shutdown complete.
INFO: Finished server process [44236]
Process SpawnProcess-1:
Traceback (most recent call last):
File "C:\Users\Jhn\.pyenv\pyenv-win\versions\3.9.10\lib\multiprocessing\process.py", line 315, in _bootstrap
self.run()
File "C:\Users\Jhn\.pyenv\pyenv-win\versions\3.9.10\lib\multiprocessing\process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "F:\_test_projects\uvicorn\.venv\lib\site-packages\uvicorn\_subprocess.py", line 78, in subprocess_started
target(sockets=sockets)
File "F:\_test_projects\uvicorn\.venv\lib\site-packages\uvicorn\server.py", line 65, in run
return asyncio.run(self.serve(sockets=sockets))
File "C:\Users\Jhn\.pyenv\pyenv-win\versions\3.9.10\lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\Jhn\.pyenv\pyenv-win\versions\3.9.10\lib\asyncio\base_events.py", line 629, in run_until_complete
self.run_forever()
File "C:\Users\Jhn\.pyenv\pyenv-win\versions\3.9.10\lib\asyncio\base_events.py", line 596, in run_forever
self._run_once()
File "C:\Users\Jhn\.pyenv\pyenv-win\versions\3.9.10\lib\asyncio\base_events.py", line 1890, in _run_once
handle._run()
File "C:\Users\Jhn\.pyenv\pyenv-win\versions\3.9.10\lib\asyncio\events.py", line 80, in _run
self._context.run(self._callback, *self._args)
File "F:\_test_projects\uvicorn\.venv\lib\site-packages\uvicorn\server.py", line 69, in serve
await self._serve(sockets)
File "C:\Users\Jhn\.pyenv\pyenv-win\versions\3.9.10\lib\contextlib.py", line 126, in __exit__
next(self.gen)
File "F:\_test_projects\uvicorn\.venv\lib\site-packages\uvicorn\server.py", line 328, in capture_signals
signal.raise_signal(captured_signal)
KeyboardInterrupt
INFO: Stopping reloader process [54420]
Jhn in F:\_test_projects\uvicorn λ
Initial Checks
Description
Hello, in the uvicorn version 0.29.0 which is the latest version on 3/30/2024 when I wrote my code updated it, and saved the changes, I saw unexpected information in the terminal that I mentioned below in the code example, where this error is not occurring in the previous versions of uvicorn like:0.27.1
Example Code
Python, Uvicorn & OS Version