diff --git a/content/django-server-sent-events.md b/content/django-server-sent-events.md index 616bd63..7ffe62a 100644 --- a/content/django-server-sent-events.md +++ b/content/django-server-sent-events.md @@ -110,15 +110,21 @@ Running the above view with the runserver results in the following error: consume asynchronous iterators in order to serve them synchronously. Use a synchronous iterator instead. -So I had to result to installing uvicorn and run my project as so: +Fortunately Daphne, the ASGI server which was developed to power Django Channels, has an async runserver which we can use: - :::bash - $ uvicorn --log-level debug --reload --timeout-graceful-shutdown 0 project.asgi:application` +To set this up we'll have to install the `daphne` package, add `daphne` to the top of our installed apps, and set +the `ASGI_APPLICATION` setting to point to our ASGI application. -The `--reload` part is particulary important when doing development, but it -does not work well when working with open connections since the server will -wait for the connection to close before reloading. This is why -`--timeout-graceful-shutdown 0` is needed. + :::python + INSTALLED_APPS = [ + "daphne", + ... + "chat", # Our app + ] + + ASGI_APPLICATION = "project.asgi.application" + +Now we can just run `./manage.py runserver` as before and we are async ready! ### More old tech to the rescue: PostgreSQL LISTEN/NOTIFY