question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Error with the reloader

See original GitHub issue

Describe 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

  1. Create a file with:
# api/index.py
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def index():
    print("boo")
    return {"Hello": "World"}
  1. run the app using uvicorn api.index:app --reload.
  2. Open the browser and call the endpoint /.
  3. Change the content of the file api/index.py so that the reloader gets triggered.
  4. 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:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
yuuuxtcommented, Dec 6, 2019

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

volumes:
 - .:/app
1reaction
dmontagucommented, Dec 4, 2019

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug report: Asked to reload your app again and again?
If you can't run your app because a message asks you to reload the app, don't press the button. Ignore it for a...
Read more >
Too many reloads??? please fix this bug or whatever it is
I exited, updated my Java from Oracle's site (version 8.something) and then logged back on here. Problem totally solved. Not a single "reload"...
Read more >
Fix "Aw, Snap!" page crashes and other page loading errors
If you receive a page loading error: To correct the problem, follow the steps below. You can begin by reloading the page. Android...
Read more >
Nagios not reloading due to config errors after dedupe patch
I've found on one particular environment that the new nagios charm's dedupe logic isn't quite working as intended.
Read more >
9435 (javascript error while reloading during animation)
I've verified this, but it looks like a bug in Firefox to me. Seems like FF must not be stopping the timer. It's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found