Class ThreadLocal
object --+
|
ThreadLocal
Thread Local Storage.
This class implements a thread-local storage facility. You create an
instance of ThreadLocal. You can get and set arbitrary attributes on that
instance, and those attributes will be thread-local. For example:
>>> local = coro.ThreadLocal()
>>> local.foo = 1
>>> local.foo
1
Now, any code that references this local object can set and get any
variable on that object, and the value will be local to that thread.
Imagine this running in another thread:
>>> local.foo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "local.pyx", line 35, in coro._coro.ThreadLocal.__getattr__
AttributeError: foo
>>> local.foo = 2
>>> local.foo
2
Now, in the original thread in the first example, imagine doing this:
>>> local.foo
1
Notice how the attribute stays the same value for that thread.
Tip: You can subclass ThreadLocal to add any logic you wish.
Note: This API is very similar to the one in Python (threading.local)
with 1 important difference: __slots__ are not supported. Python's
implementation allows you to add attributes that are not thread-local
by defining __slots__. This is not supported at this time.
|
|
|
|
|
|
a new object with type S, a subtype of T
|
|
|
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value |
|
|
Inherited from object :
__format__ ,
__hash__ ,
__init__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__sizeof__ ,
__str__ ,
__subclasshook__
|
Inherited from object :
__class__
|
x.__delattr__('name') <==> del x.name
- Overrides:
object.__delattr__
|
x.__getattribute__('name') <==> x.name
- Overrides:
object.__getattribute__
|
- Returns: a new object with type S, a subtype of T
- Overrides:
object.__new__
|
x.__setattr__('name', value) <==> x.name = value
- Overrides:
object.__setattr__
|