[Tutor] threading.currentThread() always same across request ?
Kent Johnson
kent37 at tds.net
Sun Apr 15 01:50:50 CEST 2007
Andreas Kostyrka wrote:
> * Kent Johnson <kent37 at tds.net> [070414 19:53]:
>> That's a good point. Does anyone know when to prefer threading.local()
>> vs thread attributes?
> It's design question, I guess:
>
> *) if you have thread subclasses, then use thread attributes.
> *) if you have standard threads, then use thread.local().
>
> The idea is, that it's "rude" to stick attributes on an object that is
> not owned by you.
>
> Rationale:
> *) Somebody might decide to make threading.Thread be a new style
> object with __slots__ => your code breaks.
>
> I know, it's unprobably, but if you derive a subclass, you can be at
> least sure that the object will have a __dict__ ;)
If you use threading.local() you can be sure the names you use don't
conflict with any attributes of the thread.
Kent
More information about the Tutor
mailing list