Multiple modules with database access + general app design?

Daniel Dittmar daniel.dittmar at sap.corp
Fri Jan 20 05:22:36 EST 2006


Frank Millman wrote:
> I have subclassed threading.Thread, and I store a number of attributes
> within the subclass that are local to the thread. It seems to work
> fine, but according to what you say (and according to the Python docs,
> otherwise why would there be a 'Local' class) there must be some reason
> why it is not a good idea. Please can you explain the problem with this
> approach.

Your design is just fine. If you follow the thread upwards, you'll 
notice that I encouraged the OP to pass everything by parameter.

Using thread local storage in this case was meant to be a kludge so that 
not every def and every call has to be changed. There are other cases 
when you don't control how threads are created (say, a plugin for web 
framework) where thread local storage is useful.

threading.local is new in Python 2.4, so it doesn't seem to be that 
essential to Python thread programming.

Daniel



More information about the Python-list mailing list