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

Iwan Vosloo iwan at reahl.org
Fri Jul 4 15:23:09 CEST 2008


On Fri, 2008-07-04 at 13:39 +0100, Matt Goodall wrote:
> Iwan Vosloo wrote:
> You're correct that Twisted Web does not allocate a thread per request.
> All requests are handled by an event loop in the main thread.

> In Twisted, the call stack tends to gets fragmented during a sequence of
> asynchronous calls because of its callback mechanism. Basically, you're
> hopping in and out of the Twisted reactor (the event mainloop) all the
> time. Leaving something in the call stack would not work at all.

Couldn't you put something in the call stack each time in the main loop,
before calling a callback (which will be popped again when that callback
returns to the main loop)?

> The ideal solution is, of course, to pass everything around to whatever
> needs it. However, there's really tedious at times.
> 
> Whatever the architecture of the web server there is always a request
> or, in case of WSGI, an env dict. Therefore, request-scope objects
> should be associated with the request.

True, but even passing a request or env dict around to everyone gets
tedious don't you think?

-i



More information about the Web-SIG mailing list