[Web-SIG] WSGI safe write callable using greenlet

Manlio Perillo manlio_perillo at libero.it
Tue Mar 30 22:29:47 CEST 2010


In this period I'm upgrading my WSGI implementation for Nginx:

I'm not only updating the code to work with recent Nginx versions (after
 2 years) but, above all, I'm cleaning up the code, removing stuff not
strictly required and hard to maintain.

I have already removed support to multiple Python subinterpreters, and
now I'm going to remove the async extensions I wrote (there will only
one very simple API, for applications using greenlets); finally I would
like to remove support to the write callable.

The problem, to put it simple, is that the write callable *can not* be
implemented in an asynchronous web server like Nginx.

I have two implementations:
* the first (not the default), simply keeps a buffer.
  This is explicitly forbidden by WSGI.
* the second puts the Nginx connection socket in synchronous mode;
  it works but it is something that *should not* be done.

So, I was thinking: what about a WSGI middleware that, using greenlets,
expose to the application a write callable with the correct code flow?

Here is a very first draft:

It should work with every standard WSGI implementation.

I would really like to recevive feeback about this implementation, since
I have never used greenlets before.

P.S.: LICENSE is a MIT license

Thanks   Manlio

More information about the Web-SIG mailing list