Trying to use threading.local()
Peter Otten
__peter__ at web.de
Thu Sep 13 08:22:04 EDT 2018
Antoon Pardon wrote:
> On 12-09-18 22:14, Peter Otten wrote:
>> As I understand it you need one local() instance that is shared by all
>> workers. Every thead will then see thread-specific values.
>
> It has always puzzled me how this is useful. The times I work with
> threads, I just put thread specific values in the local variables of the
> thread function.
That would be my preferred approach, too. Passing around variables through
multiple levels of function calls may be inconvenient, but global variables
tend to cause more trouble in the long run.
> What is gained by using threading.local instances?
It's magic; it confuses the uninitiated ;)
More information about the Python-list
mailing list