Well, the exception is telling you that the thread._local
object returned from threading.local()
doesn't have a value
attribute that you can assign val
to. You can confirm that by adding a dir(self.test_var)
after the self.test_var=threading.local()
line. That returns this for me:
['__class__', '__delattr__', '__dict__', '__doc__', '__getattribute__', '__hash__',
'__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__str__']
Indeed, help(threading.local())
will show you the methods and attributes that do exist - value
is not among them.
If you are attempting to add a new attribute, then perhaps you want:
self.test_var.__setattr__('value',val)
This will actually create the attribute and assign the value to it.
Instance attributes are not generally created simply by assigning to them, like non-instance variables are...