Just a heads up that currently Django is not cleaning up open PostgreSQL connections when ran in ASGI mode, leading to too many open connections error: https://code.djangoproject.com/ticket/33497
I'll have zero trust running async Django until all sync_to_async and async_to_sync calls are removed from the code base.
Writing a chat application in Django 4.2 using async StreamingHttpResponse
11–20 of 36 posts
Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#12Earlier quoted context omitted.
that’s kind of a dealbreaker
could this be addressed by something like pgbouncer or another connection pooler?
[0] http://www.pgbouncer.org/features.html#fn:2Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#13Just a heads up that currently Django is not cleaning up open PostgreSQL connections when ran in ASGI mode, leading to too many open connections error: https://code.djangoproject.com/ticket/33497
I'll have zero trust running async Django until all sync_to_async and async_to_sync calls are removed from the code base.
Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#14All the new asyncIO stuff in Django is awesome, they are doing a phenomenal job retrofitting it all to an inherently sync designed framework. One thing to note, it's been possible to build these sort of things with Django by using Gevent and Gunicorn for over a decade, and it works well. In many ways I wish Gevent had been adopted by Python rather than AsyncIO.
Also, what was the reason not to go with Gevent?
Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#15All the new asyncIO stuff in Django is awesome, they are doing a phenomenal job retrofitting it all to an inherently sync designed framework. One thing to note, it's been possible to build these sort of things with Django by using Gevent and Gunicorn for over a decade, and it works well. In many ways I wish Gevent had been adopted by Python rather than AsyncIO.
Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#16Earlier quoted context omitted.
I'll have zero trust running async Django until all sync_to_async and async_to_sync calls are removed from the code base.
Care to elaborate?
I have zero trust in this code and I have been bitten by fixes to this library that introduced deadlocks in my own code.
[1] https://github.com/django/asgiref#synchronous-code--threads.
[2] https://github.com/django/asgiref/blob/main/asgiref/sync.py#...
Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#17All the new asyncIO stuff in Django is awesome, they are doing a phenomenal job retrofitting it all to an inherently sync designed framework. One thing to note, it's been possible to build these sort of things with Django by using Gevent and Gunicorn for over a decade, and it works well. In many ways I wish Gevent had been adopted by Python rather than AsyncIO.
Where can I learn more about this? I've been thinking of trying to integrate Supabase Realtime ( https://github.com/supabase/realtime ) into my Django app (without the rest of Supabase), but I'd also like to keep things even simpler if possible. Also, what was the reason not to go with Gevent?
The biggest downside of Gevent IMO is that it enables the magic of turning sync code into async code via monkey patching things like the socket lib. This lack of explicitness can make things a bit difficult to reason about, without a good mental model of what Gevent is doing underneath the hood.
Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#18Earlier quoted context omitted.
Care to elaborate?
Look at the intended semantics [1], and then read the implementation [2]. Can you figure out if the implementation is correct? Can you infer the possible limitations of the approach at glance? Can your async library actually handle being called with multiple event loops installed? I have zero trust in this code and I have been bitten by fixes to this library that introduced deadlocks in my own code. [1] https://githu…
Is there anything else in Python-land you would go with for the use case you have in mind? Or does pretty much all the async stuff turn on you like this, at some point or another?
Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#19Re: Writing a chat application in Django 4.2 using async StreamingHttpResponse
#20Do modern chat actually use websocket and the like? Discord / Slack on the web ( browser ) what do they use?