Fix memory leak in cached_property.
This commit is contained in:
parent
96d9386e77
commit
f53eeed63b
1 changed files with 5 additions and 2 deletions
|
|
@ -23,11 +23,14 @@ from threading import Lock
|
|||
def cached_property(fun):
|
||||
"""A memoize decorator for class properties."""
|
||||
lock = Lock()
|
||||
locks = defaultdict(Lock)
|
||||
@functools.wraps(fun)
|
||||
def get(self):
|
||||
with lock:
|
||||
obj_lock = locks[self, fun]
|
||||
try:
|
||||
obj_locks = self._locks
|
||||
except AttributeError:
|
||||
obj_locks = self._locks = defaultdict(Lock)
|
||||
obj_lock = obj_locks[fun]
|
||||
with obj_lock:
|
||||
try:
|
||||
cache = self._cache
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue