[Web-SIG] Alternative to threading.local, based on the stack
Ian Bicking
ianb at colorstudy.com
Fri Jul 4 21:10:27 CEST 2008
Iwan Vosloo wrote:
> Many web frameworks and ORM tools have the need to propagate data
> depending on some or other context within which a request is dealt with.
> Passing it all via parameters to every nook of your code is cumbersome.
>
> A lot of the frameworks use a thread local context to solve this
> problem. I'm assuming these are based on threading.local.
>
> (See, for example:
> http://www.sqlalchemy.org/docs/05/session.html#unitofwork_contextual )
>
> Such usage assumes that one request is served per thread.
>
> This is not necessarily the case. (Twisted would perhaps be an example,
> but I have not checked how the twisted people deal with the issue.)
The Spawning server
(http://ulaluma.com/pyx/archives/2008/06/spawning_01_rel.html) would
indeed get things mixed up this way, as uses greenlets to make (at least
some) blocking calls async. So it would encounter this problem full-force.
To throw another wrench in things, with the Paste/WebError evalexception
interactive exception handler, it restores this thread-local context so
you can later execute expressions in the same context.
--
Ian Bicking : ianb at colorstudy.com : http://blog.ianbicking.org
More information about the Web-SIG
mailing list