Background: I've been writing an enhancement to the web2py application 
framework, which for purposes of this question can (I think) be viewed as just 
another wsgi app.

The legacy code has a module variable that contains a set of URL-rewriting 
parameters. That variable is referenced at various points in a requests 
lifetime. The enhancement (I won't bother with a lot of detail) establishes 
multiple sets of these parameters. A set is chosen when a request first comes 
in, and is used for its lifetime.

I think it's obvious that this isn't thread-safe. The easiest and most elegant 
fix would be to use threading.local to create a bit of thread-local storage to 
store the parameters during a request.

This should work fine with web2py's embedded server (Rocket, which is native 
Python and uses the threading module), and I assume it would work for threads 
created by mod_wsgi.

What I'm less certain of is whether it will also be safe for Apache worker 
threads. I'm frankly more than a little confused on the subject, and I don't 
really understand the mechanism that threading.local is using in the first 
place. 

So: a) should threading.local be thread-safe against Apache worker threads, and 
b) if not, is there another approach that might work better? That is, some 
other approach to thread-local storage that would work with Apache threads.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to