Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit b0a0700

Browse files
committed
Fix some races with threading.local
See #86 This does not fix races where the _localimpl is delete by another thread... but I don't think the _threading_local implementation is actually used.
1 parent 28bee44 commit b0a0700

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Lib/_threading_local.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def local_deleted(_, key=key):
171171
# When the localimpl is deleted, remove the thread attribute.
172172
thread = wrthread()
173173
if thread is not None:
174-
del thread.__dict__[key]
174+
del thread._locals[key]
175175
def thread_deleted(_, idt=idt):
176176
# When the thread is deleted, remove the local dict.
177177
# Note that this is suboptimal if the thread object gets
@@ -182,7 +182,7 @@ def thread_deleted(_, idt=idt):
182182
dct = local.dicts.pop(idt)
183183
wrlocal = ref(self, local_deleted)
184184
wrthread = ref(thread, thread_deleted)
185-
thread.__dict__[key] = wrlocal
185+
thread._locals[key] = wrlocal
186186
self.dicts[idt] = wrthread, localdict
187187
return localdict
188188

Lib/threading.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ class is implemented.
808808
# Copy of sys.stderr used by self._invoke_excepthook()
809809
self._stderr = _sys.stderr
810810
self._invoke_excepthook = _make_invoke_excepthook()
811+
self._locals = {}
811812
# For debugging and _after_fork()
812813
_dangling.add(self)
813814

0 commit comments

Comments
 (0)