Just from experience... Yes.  I use threading.local extensively with
mod_wsgi.  Check out threading.enumerate() sometime, and you will see the
actual python threads in use, despite the fact they are created outside of
python.

Now, I was using daemon mode when last testong, so maybe someone else can
comment on.embedded mode...  But I suspect that it will work as advertised
in any event.

Jason Garber

On Sep 7, 2010 5:59 PM, "Jonathan Lundell" <[email protected]> wrote:

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]<modwsgi%[email protected]>
.
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=en.

-- 
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