summaryrefslogtreecommitdiffstats
path: root/Lib/_weakrefset.py
diff options
context:
space:
mode:
authorKumar Aditya <kumaraditya@python.org>2024-10-13 15:35:05 (GMT)
committerGitHub <noreply@github.com>2024-10-13 15:35:05 (GMT)
commitcd0f9d111a040ad863c680e9f464419640c8c3fd (patch)
tree8bb24147b6b0e69f406286ee456817fb50e9026a /Lib/_weakrefset.py
parent08489325d1cd94eba97c5f5f8cac49521fd0b0d7 (diff)
downloadcpython-cd0f9d111a040ad863c680e9f464419640c8c3fd.zip
cpython-cd0f9d111a040ad863c680e9f464419640c8c3fd.tar.gz
cpython-cd0f9d111a040ad863c680e9f464419640c8c3fd.tar.bz2
gh-89967: make WeakKeyDictionary and WeakValueDictionary thread safe (#125325)
Make `WeakKeyDictionary` and `WeakValueDictionary` thread safe by copying the underlying the dict before iterating over it.
Diffstat (limited to 'Lib/_weakrefset.py')
-rw-r--r--Lib/_weakrefset.py25
1 files changed, 0 insertions, 25 deletions
diff --git a/Lib/_weakrefset.py b/Lib/_weakrefset.py
index 2071755..d1c7fca 100644
--- a/Lib/_weakrefset.py
+++ b/Lib/_weakrefset.py
@@ -8,31 +8,6 @@ from types import GenericAlias
__all__ = ['WeakSet']
-class _IterationGuard:
- # This context manager registers itself in the current iterators of the
- # weak container, such as to delay all removals until the context manager
- # exits.
- # This technique should be relatively thread-safe (since sets are).
-
- def __init__(self, weakcontainer):
- # Don't create cycles
- self.weakcontainer = ref(weakcontainer)
-
- def __enter__(self):
- w = self.weakcontainer()
- if w is not None:
- w._iterating.add(self)
- return self
-
- def __exit__(self, e, t, b):
- w = self.weakcontainer()
- if w is not None:
- s = w._iterating
- s.remove(self)
- if not s:
- w._commit_removals()
-
-
class WeakSet:
def __init__(self, data=None):
self.data = set()