Fix deadlocks in cached_property().
This commit is contained in:
parent
a373765d3d
commit
5f1273fd18
1 changed files with 3 additions and 5 deletions
|
|
@ -16,20 +16,18 @@
|
|||
|
||||
import functools
|
||||
import itertools
|
||||
from collections import defaultdict
|
||||
from threading import Lock
|
||||
|
||||
|
||||
def cached_property(fun):
|
||||
"""A memoize decorator for class properties."""
|
||||
lock = Lock()
|
||||
locks = {}
|
||||
locks = defaultdict(Lock)
|
||||
@functools.wraps(fun)
|
||||
def get(self):
|
||||
with lock:
|
||||
try:
|
||||
obj_lock = self._lock
|
||||
except AttributeError:
|
||||
obj_lock = self._lock = Lock()
|
||||
obj_lock = locks[self, fun]
|
||||
with obj_lock:
|
||||
try:
|
||||
cache = self._cache
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue