Lines Matching refs:thread
8 Thread-local objects support the management of thread-local data.
9 If you have data that you want to be local to a thread, simply create
10 a thread-local object and use its attributes:
26 What's important about thread-local objects is that their data are
27 local to a thread. If we access the data in a different thread:
37 >>> thread = threading.Thread(target=f)
38 >>> thread.start()
39 >>> thread.join()
43 we get different data. Furthermore, changes made in the other thread
44 don't affect data seen in this thread:
50 attribute, are for whatever thread was current at the time the
52 these values across threads, as they apply only to the thread they
66 called each time the local object is used in a separate thread. This
67 is necessary to initialize each thread's dictionary.
89 As before, we can access the data in a separate thread:
92 >>> thread = threading.Thread(target=f)
93 >>> thread.start()
94 >>> thread.join()
98 without affecting this thread's data:
107 Note that subclasses can define slots, but they are not thread
117 So, the separate thread:
119 >>> thread = threading.Thread(target=f)
120 >>> thread.start()
121 >>> thread.join()
138 # isn't compiled in to the `thread` module. This creates potential problems
142 # for locals in the `thread` module, and there is no circular import problem
147 """A class managing thread-local dicts"""
155 # { id(Thread) -> (ref(Thread), thread-local dict) }
159 """Return the dict for the current thread. Raises KeyError if none
161 thread = current_thread()
162 return self.dicts[id(thread)][1]
165 """Create a new dict for the current thread, and return it."""
168 thread = current_thread()
169 idt = id(thread)
171 # When the localimpl is deleted, remove the thread attribute.
172 thread = wrthread()
173 if thread is not None:
174 del thread.__dict__[key]
176 # When the thread is deleted, remove the local dict.
177 # Note that this is suboptimal if the thread object gets
179 # as soon as the OS-level thread ends instead.
184 wrthread = ref(thread, thread_deleted)
185 thread.__dict__[key] = wrlocal
215 # We need to create the thread dict in anticipation of