[Web-SIG] WSGI and greenlets

Manlio Perillo manlio_perillo at libero.it
Thu May 22 10:51:09 CEST 2008


Christopher Stawarz ha scritto:
> On May 7, 2008, at 4:44 AM, Manlio Perillo wrote:
> [...]
>> I don't think this will solve the problem.
>> Moreover in your example you buffer the whole request body so that you 
>> have to yield only one time.
> 
> Your example was:
> 
> def application(environ, start_response):
>   def nested():
>      while True:
>         poll(xxx)
>         yield ''
>      yield result
> 
>   for r in nested():
>      if not r:
>          yield ''
> 
>   yield r
> 
> My suggestion would allow you to rewrite this like so:
> 
> @awsgiref.callstack.add_callstack
> def application(environ, start_response):
>   def nested():
>      while True:
>         poll(xxx)
>         yield ''
>      yield result
> 
>   yield nested()
> 
> The nesting can be arbitrarily deep, so nested() could yield 
> doubly_nested() and so on.  While not as elegant as greenlets, I think 
> this does address your concern.
> 


I'm reading the PEP 342, and I still think that this will not work as I 
want for Nginx (where I have no control over the "scheduler").

In fact the PEP 342 says:
"""However, if it were possible to pass values or exceptions *into* a
generator at the point where it was suspended, a simple co-routine
scheduler or "trampoline function" would let coroutines "call" each
other without blocking."""



However writing a co-routine scheduler or "trampoline function" when 
your application is embedded in an external server is not possible (but 
please, correct me if I'm wrong).




 > [...]


Regards   Manlio Perillo


More information about the Web-SIG mailing list