Is it possible to use ASGI in development" Especially when the cloud platform I am deploying to uses ASGI, and certain code behaves differently in production from development. I have synchronous code which works beautifully in development and terribly in production. I don’t need asynchronous code throughout my application. Only for one case in my views and then in my javascript related to that view. Is it possible to set up an ASGI server in development so that I would know what to expect in production?
See the docs for How to use Django with Daphne - there’s a section in there about its integration with runserver
.
Side note: If you’re using Windows in either your development or your deployment environment, you are likely to face performance-related issues. Daphne/Twisted and Windows apparently don’t “play nice” together. (See this thread for a recent example: Django Channels with Redis slow intialization)
I have only ever deployed Daphne to Linux and have never faced any performance-related issues. Everyone I know who have tried to deploy it to Windows has faced some type of problem.
Hi @KenWhitesell , thanks so much for your response. I am not on Windows. I am on Mac. I checked out the documentation and tried to install and use Daphne, but then I got back the error that my database was not properly configured.
I tried installing and using Daphne again. This time, I double checked in the docs, and my error was that I didn’t place Daphne at the top of INSTALLED_APPS. Now it works. The likes are working pretty well in development, but terribly on render. I wonder why that is. Am investigating. Thanks for your help @KenWhitesell!
@KenWhitesell I checked again because Daphne was not being added to requirements.txt. 4.1.2 does not support python 3.13.0, and that is the version I am on. 4,.2 will support it whenever that comes out. What a pain. I was wondering why things were working so smoothly.
As far as I am aware there’s no incompatibility between the current Daphne version and Python 3.13. The commit adding official support only updated metadata and testing configurations.
Well, in the official GitHub repository, it explicitly stated that support for Python 3.13.0 would only be available in 4.2. And, when I checked my updated requirements.txt, it was not listed. And, subsequently, when I deployed to Render, the build failed.
You should be able to add daphne==4.1.2
to that file, I think. (My point was only that official compatibility is only a paperwork thing: there’s no actual incompatibility, so as long as Daphne is installed it should work.)
You mean to add it manually? I don’t know about that… There must be a reason that pip install -r requirements
would not add it.
The pip
command (only) installs the dependencies listed in the requirements.txt
file. If Daphne is missing from there then it won’t be installed.
It’s necessary to add your dependencies to your requirements file so that they’ll be installed.
You can see what’s installed locally by running pip list
or pip freeze
and compare that to the contents of your requirements.txt
file.
I know all that. However, because it is incompatible with my version of Python, even thought I add it with pip in my virtual environment, it does not get added to my requirements.txt. I already did a pip list and pip freeze. It is listed there. However, when I run pip install -r requirements.txt it does not get added. And when that command is run on Render, it also doesn’t get added. Then the build fails. So I am just waiting until 4.2 comes out.
OK, so I’m not sure how you’re generating your requirements.txt
file. It used to be pip freeze > requirements.txt
Again though, Daphne 4.1.2 is not incompatible with Python 3.13. The official support literally only adds the metadata to declare that support, but there’s not upper version bound. You could try adding it to your requirements.
Otherwise, yes, that’ll be the other option.
Good luck!
Thanks! I am learning ALOT with this project. That’s the only way through trial and error.