Local class variables? (mod_python problem)
Diez B. Roggisch
deets at nospam.web.de
Fri Feb 23 12:54:55 EST 2007
>
> Many thanks for your reply. The use case is per request, and I would be
> grateful to learn more about thread-local storage.
There are several ways. I'm not familiar with mod_python, but I guess you
get a dict-like object for the request parameters. In python, this is
usually writable (in contrast to the darn J2EE-spec'ed HttpRequest)
So just add a new key, e.g. "working_state", to it. Under that, file those
variables.
Alternatively, there are recipes out there
(http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/302088
)
that give you basically a dictionary keyed with the current thread.
That is helpful if you have computations deeper in code that can't get a
hold on the request object. Might be the case in mod_python - in cherrypy,
the request itself is thread-locally stored, so you can get it whereever
you need.
Diez
More information about the Python-list
mailing list