[BUG] Error with the reloader
See original GitHub issueDescribe the bug
Whenever I do
uvicorn api.index:app --reload
Then change the file index, I get an error like this
Accept failed on a socket
socket: <asyncio.TransportSocket fd=592, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 8000)>
(See the full log below)
To Reproduce
- Create a file with:
# api/index.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def index():
print("boo")
return {"Hello": "World"}
- run the app using
uvicorn api.index:app --reload
. - Open the browser and call the endpoint
/
. - Change the content of the file api/index.py so that the reloader gets triggered.
- I expected it to reload the server, instead the error specified below happened.
Expected behavior
Reload the application, and continue to work as normal.
Environment
- OS: Windows
- FastAPI Version [e.g. 0.3.0]:
python -c "import fastapi; print(fastapi.__version__)"
email-validator not installed, email fields will be treated as str.
To install, run: pip install email-validator
0.44.0
- Python version:
python --version
Python 3.8.0
Logs
uvicorn index:app --reload ?[32mINFO?[0m: Uvicorn running on ?[1mhttp://127.0.0.1:8000?[0m (Press CTRL+C to quit) ?[32mINFO?[0m: Started reloader process [?[36m?[1m1232?[0m] ?[33mWARNING?[0m: email-validator not installed, email fields will be treated as str. To install, run: pip install email-validator ?[32mINFO?[0m: Started server process [?[36m13256?[0m] ?[32mINFO?[0m: Waiting for application startup. ?[32mINFO?[0m: Application startup complete. ?[33mWARNING?[0m: Detected file change in ‘index.py’. Reloading… ?[33mWARNING?[0m: email-validator not installed, email fields will be treated as str. To install, run: pip install email-validator ?[32mINFO?[0m: Started server process [?[36m1064?[0m] ?[31mERROR?[0m: Accept failed on a socket socket: <asyncio.TransportSocket fd=592, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=(‘127.0.0.1’, 8000)> Traceback (most recent call last): File “C:\Users\wass1\AppData\Local\Programs\Python\Python38\Lib\asyncio\proactor_events.py”, line 817, in loop f = self._proactor.accept(sock) File “C:\Users\wass1\AppData\Local\Programs\Python\Python38\Lib\asyncio\windows_events.py”, line 545, in accept self._register_with_iocp(listener) File “C:\Users\wass1\AppData\Local\Programs\Python\Python38\Lib\asyncio\windows_events.py”, line 714, in _register_with_iocp _overlapped.CreateIoCompletionPort(obj.fileno(), self._iocp, 0, 0) OSError: [WinError 87] The parameter is incorrect ?[32mINFO?[0m: Waiting for application startup. ?[32mINFO?[0m: Application startup complete.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
I encountered this issue too. I turned to use docker and it won’t bother. Here’s what I found, hope it helps:
use tiangolo/uvicorn-gunicorn and use
CMD /start-reload.sh
in Dockerfile;set volume in the docker-compose.yml
I believe this is an issue with uvicorn on Windows. I think if you use the asyncio event loop the issue goes away. I can’t easily look for them now but I recall one or two recent issues where this was raised and solved. @euri10 might know more?