This commit is contained in:
Víðir Valberg Guðmundsson 2023-05-17 15:18:15 +02:00
parent c8259c3743
commit b23ce26055
1 changed files with 13 additions and 7 deletions

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. consume asynchronous iterators in order to serve them synchronously.
Use a synchronous iterator instead. 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 To set this up we'll have to install the `daphne` package, add `daphne` to the top of our installed apps, and set
$ uvicorn --log-level debug --reload --timeout-graceful-shutdown 0 project.asgi:application` the `ASGI_APPLICATION` setting to point to our ASGI application.
The `--reload` part is particulary important when doing development, but it :::python
does not work well when working with open connections since the server will INSTALLED_APPS = [
wait for the connection to close before reloading. This is why "daphne",
`--timeout-graceful-shutdown 0` is needed. ...
"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 ### More old tech to the rescue: PostgreSQL LISTEN/NOTIFY