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

django-browser-reload prevents uvicorn reload #255

Closed
roushikk opened this issue Apr 10, 2024 · 1 comment
Closed

django-browser-reload prevents uvicorn reload #255

roushikk opened this issue Apr 10, 2024 · 1 comment

Comments

@roushikk
Copy link

Python Version

3.12.2

Django Version

4.2.11

Package Version

1.12.1

Browser

Chrome 123

Description

When django-browser-reload is enabled and we open a connection, it prevents uvicorn reload to trigger. The reload gets stuck on the following for infinite amount of time:

WARNING:  WatchFiles detected changes in 'narcissus/components/meow.py'. Reloading...
INFO:     Shutting down
INFO:     Waiting for connections to close. (CTRL+C to force quit)

Adding --timeout-graceful-shutdown 2 makes the reload possible with the following message:

WARNING:  WatchFiles detected changes in 'narcissus/components/meow.py'. Reloading...
INFO:     Shutting down
INFO:     Waiting for connections to close. (CTRL+C to force quit)
ERROR:    Cancel 1 running task(s), timeout graceful shutdown exceeded   <-- Indicates a running task that is not shutting down on uvicorn reload signal
INFO:     Finished server process [1169]
INFO:     Started server process [2964]
INFO:     Waiting for application startup.
INFO:     ASGI 'lifespan' protocol appears unsupported.
INFO:     Application startup complete.
INFO:     172.18.0.1:51234 - "GET /__reload__/events/ HTTP/1.1" 200 OK

I think the following lines in src/django_browser_reload/views.py might be the reason for this behaviour:

async def event_stream() -> AsyncGenerator[bytes, None]:
    while True:
        await asyncio.sleep(PING_DELAY)
        yield message("ping", versionId=version_id)

        if should_reload_event.is_set():
            should_reload_event.clear()
            yield message("reload")
@adamchainz
Copy link
Owner

django-browser-reload works by having an infinite streaming response: https://github.com/adamchainz/django-browser-reload#how-it-works . I think you’ll need to find a way to stop uvicorn from waiting for connections to close to make these two tools work together. Not really anything we can do in this package as it’s unaware of the host server’s state.

@adamchainz adamchainz closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
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

2 participants