Leverage Django 3.1+ async views to implement SSE

124 views
Skip to first unread message

Benoit Blanchon

unread,
Aug 22, 2020, 4:46:50 AM8/22/20
to Django users
Hi,

Documentation for Django 3.1 says this about async views:

The main benefits are the ability to service hundreds of connections without using Python threads. This allows you to use slow streaming, long-polling, and other exciting response types.

I believe this means we could implement an SSE (Server-Sent Events) view without monopolizing a thread per client, but I didn't figure out exactly how.

I know about Django Channels, but I'm curious to see if we can avoid it. 

I initially thought StreamingHttpResponse was the way to go since it has been used successfully to implement SSE with synchronous views. Still, I would accept any solution based on asynchronous views.

I opened a bounty on stack-overflow, but so far, no viable solution was proposed.  

Does anyone know how we could leverage async views to implement SSE?

Best regards,
Benoit Blanchon





Reply all
Reply to author
Forward
0 new messages