toolrack.threading¶
Thread-related utilities.
-
class
toolrack.threading.
ThreadLocalAttribute
(name)¶ Descriptor to proxy access to a class attribute, making it thread-local.
This descriptor can be used to make a class attribute thread-local in a trasparent way:
class MyClass: attr = ThreadLocalAttribute('attr') instance = MyClass()
The attribute will be normally accessible as
instance.attr
, but it’s stored in athreading.local()
context.
-
toolrack.threading.
thread_local_attrs
(*attrs)¶ Class decorator to make attributes storage thread-local.
It should be passed names of attributes in the decorated class to make local:
@thread_local_attrs('foo', 'bar') class MyClass: foo = 3 bar = None