Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Considering ASGI. #179

Open
tomchristie opened this issue Apr 4, 2018 · 5 comments · May be fixed by #359
Open

Considering ASGI. #179

tomchristie opened this issue Apr 4, 2018 · 5 comments · May be fixed by #359

Comments

@tomchristie
Copy link

Okay, I'm going to punt this one out there.

Andrew Godwin's latest work on the ASGI spec, means that there really is now an asyncio-based interface for Python webservers.

I'm planning to shortly be releasing a new release of uvicorn, at which point there will be two production-ready ASGI servers. (We already have daphne available.)

I'll also be releasing a new version of apistar which will present either WSGI or ASGI interfaces, so there will be at least two ASGI web application frameworks. (We already have Django Channels)

I already use whitenoise for serving static files with apistar, but it's not ideal under ASGI, because we necessarily need to run whitenoise behind as WSGI-to-ASGI adapter, which means that:

  • We're not actually running asyncio code for disk operations.
  • We're not able to stream response data, instead everything gets buffered at the adapter layer.
  • There's no support for send_file. (This isn't currently addressed in the ASGI spec, so that's more complicated to address.)

This may well be premature, given the early nature of ASGI, but I'm wondering if you'd consider whitenoise-as-an-ASGI-middleware. If we use sync file operations on load, then I think ASGI support could be addressed with...

  • A WhiteNoise subclass, ASGIWhiteNoise that overrides __call__, and serve.
  • Changing get_response and file iteration in the asyncio case, to use something like aiofiles.
  • Considering how a sendfiles extension to ASGI might look.

I'll likely be tackling some of this as part of my work on apistar, but figured I'd also raise this here just to get an idea of if you'd be interested in seeing ASGI supported directly in whitenoise?

@evansd
Copy link
Owner

evansd commented Apr 4, 2018

Hi Tom, thanks for raising this. Yes, I'd definitely be interested in supporting native ASGI in WhiteNoise. My hope is that it won't actually involve a lot of extra code. Fundamentally, WhiteNoise takes a request path, HTTP method, and headers and returns a status code, response headers, and an open file handle. There's a bit of adaptor code to get this to work with the WSGI and Django middleware specs. So hopefully the ASGI adaptor code will be equally small, but I haven't looked into this in detail yet.

I don't know exactly when I'll get time to look at this (the WhiteNoise 4.0 release is already massively behind due to work and family commitments) but very happy to review patches or discuss options.

@tomchristie
Copy link
Author

I've put together #181, to demonstrate the scope of changes.

The most obvious problem would be that using async/await syntax makes the codebase no longer be 2.7 compatible.

@chickeaterbanana
Copy link

In version 5.0 python 2.7 support is dropped so is this a option again?

@evansd
Copy link
Owner

evansd commented Feb 28, 2020

Yes, absolutely. It's "just" a case of finding the time.

@troygrosfield
Copy link

troygrosfield commented Apr 22, 2021

@evansd see my comment about possibly moving this project to JazzBand to get the community more involved:

#261 (comment)

@Archmonger Archmonger linked a pull request Jun 22, 2023 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants