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

Martijn Faassen faassen at startifact.com
Fri Jul 4 14:05:15 CEST 2008


Hey,

On Fri, Jul 4, 2008 at 1:37 PM, Iwan Vosloo <iwan at reahl.org> wrote:
> On Fri, 2008-07-04 at 13:31 +0200, Martijn Faassen wrote:
>> scoped_session is actually, I think, a bad example, as SQLAlchemy uses
>> the thread id to scope things per session, not threading.local. As
>> long as there's a way to uniquely identify "context", scoped_session
>> could also be scoped differently, as long as it has a way identify the
>> context that doesn't need any non-global parameters.
>>
>> Zope 3 may be a better example, as it does use thread locals to scope
>> things per thread (I believe this requirement by Zope was actually one
>> of the reasons this feature was moved into Python). There may also be
>> other parts of SQLAlchemy that indeed use thread local variables.
>
> Point taken, I'm not familiar with the implementation of scoped_session.
> But still, it is the same idea as that implemented in threading.local,
> isn't it?

Yes, I think so, except that scoped_session is more flexible than that
and could actually be convinced to use your technique for
identification of scope as well.

Regards,

Martijn


More information about the Web-SIG mailing list