##// END OF EJS Templates
refactored lazy properties little bit for ThreadecLocal to work better
marcink -
r3475:f134d125 beta
parent child Browse files
Show More
@@ -1,3 +1,14 b''
1 class _Missing(object):
2
3 def __repr__(self):
4 return 'no value'
5
6 def __reduce__(self):
7 return '_missing'
8
9 _missing = _Missing()
10
11
1 12 class LazyProperty(object):
2 13 """
3 14 Decorator for easier creation of ``property`` from potentially expensive to
@@ -24,8 +35,11 b' class LazyProperty(object):'
24 35 def __get__(self, obj, klass=None):
25 36 if obj is None:
26 37 return self
27 result = obj.__dict__[self.__name__] = self._func(obj)
28 return result
38 value = obj.__dict__.get(self.__name__, _missing)
39 if value is _missing:
40 value = self._func(obj)
41 obj.__dict__[self.__name__] = value
42 return value
29 43
30 44 import threading
31 45
@@ -41,5 +55,8 b' class ThreadLocalLazyProperty(LazyProper'
41 55 if not hasattr(obj, '__tl_dict__'):
42 56 obj.__tl_dict__ = threading.local().__dict__
43 57
44 result = obj.__tl_dict__[self.__name__] = self._func(obj)
45 return result
58 value = obj.__tl_dict__.get(self.__name__, _missing)
59 if value is _missing:
60 value = self._func(obj)
61 obj.__tl_dict__[self.__name__] = value
62 return value
General Comments 0
You need to be logged in to leave comments. Login now