[Web-SIG] Alternative to threading.local, based on the stack

Manlio Perillo manlio_perillo at libero.it
Tue Jul 8 21:47:09 CEST 2008


Donovan Preston ha scritto:
> 
> On Jul 8, 2008, at 11:45 AM, Manlio Perillo wrote:
> 
>> Using greenlets, there is always a current greenlet, so you can use 
>> this for local storage.
>>
>> A library function can check if there is an active greenlet, and use 
>> it as data key; otherwise it will use the current thread id.
> 
> Yes, this is exactly what I did in the 
> wrap_threading_local_with_coro_local here:
> 
> http://donovanpreston.com:8888/eventlet/file/b6f9627e88df/eventlet/util.py
> 

Ok.

>> However this will not work if you have an asynchronous server that 
>> does not make use of greenlets.
> 
> Exactly, which is why I am proposing just standardizing something that 
> does exactly what people use threading.local for, but whose 
> implementation is pluggable by the wsgi server.
> 

But this will be not easy to implement, especially if it should go in a 
separate module.


Maybe its better to have something like:

wsgiorg.local_scope
a function that returns the current request id.

The function itself is not bound to the current request, so it can be 
safely stored.

Maybe this should be more easy to implement, I'm not sure.




Manlio Perillo


More information about the Web-SIG mailing list