Skip to content

django-browser-reload prevents uvicorn reload #255

@roushikk

Description

@roushikk

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")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions