This commit is contained in:
Víðir Valberg Guðmundsson 2023-05-17 15:18:15 +02:00
parent c8259c3743
commit b23ce26055

View file

@ -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