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