Package coro :: Module _coro :: Class ThreadLocal
[hide private]
[frames] | no frames]

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.

Instance Methods [hide private]
 
__delattr__(...)
x.__delattr__('name') <==> del x.name
 
__getattr__(...)
 
__getattribute__(...)
x.__getattribute__('name') <==> x.name
a new object with type S, a subtype of T
__new__(T, S, ...)
 
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Inherited from object: __format__, __hash__, __init__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__delattr__(...)

 
x.__delattr__('name') <==> del x.name
Overrides: object.__delattr__

__getattribute__(...)

 
x.__getattribute__('name') <==> x.name
Overrides: object.__getattribute__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

__setattr__(...)

 
x.__setattr__('name', value) <==> x.name = value
Overrides: object.__setattr__