Skip to content

Commit

Permalink
Fix some races with threading.local
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
colesbury committed Aug 13, 2020
1 parent 28bee44 commit b0a0700
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/_threading_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def local_deleted(_, key=key):
# When the localimpl is deleted, remove the thread attribute.
thread = wrthread()
if thread is not None:
del thread.__dict__[key]
del thread._locals[key]
def thread_deleted(_, idt=idt):
# When the thread is deleted, remove the local dict.
# Note that this is suboptimal if the thread object gets
Expand All @@ -182,7 +182,7 @@ def thread_deleted(_, idt=idt):
dct = local.dicts.pop(idt)
wrlocal = ref(self, local_deleted)
wrthread = ref(thread, thread_deleted)
thread.__dict__[key] = wrlocal
thread._locals[key] = wrlocal
self.dicts[idt] = wrthread, localdict
return localdict

Expand Down
1 change: 1 addition & 0 deletions Lib/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ class is implemented.
# Copy of sys.stderr used by self._invoke_excepthook()
self._stderr = _sys.stderr
self._invoke_excepthook = _make_invoke_excepthook()
self._locals = {}
# For debugging and _after_fork()
_dangling.add(self)

Expand Down

0 comments on commit b0a0700

Please sign in to comment.