Running whitenoise behind a WSGI-to-ASGI adapter
See original GitHub issueI’m about to deploy a django app. I was originally going to use uvicorn
with Django 3.0, but after seeing whitenoise
doesn’t work with asgi servers yet was thinking of just reverting back to wsgi.
I just came across @tomchristie’s pull request and he mentions he’s able to (non-ideally) get it working with a wsgi-to-asgi adapter. I was wondering if there’s any additional information on how to get that working.
Ideally I’d like to just swap that out whenever whitenoise goes asgi, instead of reverting from uvicorn
to gunicorn
.
Thanks for the continued work on a great project!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Using WhiteNoise with any WSGI application
On initialization, WhiteNoise walks over all the files in the directories that have been added (descending into sub-directories) and builds a list of...
Read more >whitenoise
I have what I believe is an uncommon setup: during deploy I have both new and old application servers working simultaneously (using k8s),...
Read more >A Guide to ASGI in Django 3.0 and its Performance
A blog by Arun Ravindran, author and speaker, about Python, Django and other curious things.
Read more >How to use the whitenoise.django.DjangoWhiteNoise ...
To help you get started, we've selected a few whitenoise.django.DjangoWhiteNoise examples, based on popular ways it is used in public projects.
Read more >Issues with poetry when deploying Django application
Hi, I am following the “Getting Started With Django on Render” tutorial and all was going well until I got to “Configure Django...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi, I’ve had success in using WhiteNoiseMiddleware in an async context in Django, but I noticed that WhiteNoiseMiddleware does not inherit from MiddlewareMixin.
The consequence is that WhiteNoiseMiddleware does not get the full async compatibility layer from Django 3.1.
It would not be a full async support but maybe implementing
sync_capable=True
and being able to call an asyncget_response
(and be called as async) could be a useful improvement of WhiteNoiseMiddleware.It would reduce the time spent in the sync emulation layer (which is a separate thread with essentially zero concurrency because Django calls
sync_to_async
with thethread_sensitive=True
option) and allow async views to pass through directly when not serving a static file request.Copying the behaviour of MiddlewareMixin, it could roughly look like this:
It’s probably better to inherit from MiddlewareMixin instead of duplicating code.
In the previous code,
process_request
is called directly, which means doing disk IO in the main async thread. This is not ideal but probably not awful, I’d guess static files are very likely to be quickly available from the system cache.Hi, yes DjangoWhitenoise acts as standard Django middleware so should run fine via the compatibility layer. I’d love to get native ASGI integration into Whitenoise but super busy with the medical day job at the moment and ENOTIME 😃