Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Private Attributes
_threading_local._localimpl Class Reference
Collaboration diagram for _threading_local._localimpl:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def get_dict
def create_dict

Public Attributes

 key
 dicts

Static Private Attributes

string __slots__ = 'key'

Detailed Description

A class managing thread-local dicts

Definition at line 150 of file _threading_local.py.


Constructor & Destructor Documentation

Definition at line 154 of file _threading_local.py.

00154 
00155     def __init__(self):
00156         # The key used in the Thread objects' attribute dicts.
00157         # We keep it a string for speed but make it unlikely to clash with
00158         # a "real" attribute.
00159         self.key = '_threading_local._localimpl.' + str(id(self))
00160         # { id(Thread) -> (ref(Thread), thread-local dict) }
00161         self.dicts = {}

Here is the caller graph for this function:


Member Function Documentation

Create a new dict for the current thread, and return it.

Definition at line 168 of file _threading_local.py.

00168 
00169     def create_dict(self):
00170         """Create a new dict for the current thread, and return it."""
00171         localdict = {}
00172         key = self.key
00173         thread = current_thread()
00174         idt = id(thread)
00175         def local_deleted(_, key=key):
00176             # When the localimpl is deleted, remove the thread attribute.
00177             thread = wrthread()
00178             if thread is not None:
00179                 del thread.__dict__[key]
00180         def thread_deleted(_, idt=idt):
00181             # When the thread is deleted, remove the local dict.
00182             # Note that this is suboptimal if the thread object gets
00183             # caught in a reference loop. We would like to be called
00184             # as soon as the OS-level thread ends instead.
00185             local = wrlocal()
00186             if local is not None:
00187                 dct = local.dicts.pop(idt)
00188         wrlocal = ref(self, local_deleted)
00189         wrthread = ref(thread, thread_deleted)
00190         thread.__dict__[key] = wrlocal
00191         self.dicts[idt] = wrthread, localdict
00192         return localdict
00193 
00194 
@contextmanager

Here is the call graph for this function:

Return the dict for the current thread. Raises KeyError if none
defined.

Definition at line 162 of file _threading_local.py.

00162 
00163     def get_dict(self):
00164         """Return the dict for the current thread. Raises KeyError if none
00165         defined."""
00166         thread = current_thread()
00167         return self.dicts[id(thread)][1]

Here is the call graph for this function:


Member Data Documentation

Definition at line 152 of file _threading_local.py.

Definition at line 160 of file _threading_local.py.

Definition at line 158 of file _threading_local.py.


The documentation for this class was generated from the following file: