(fn)
| 41 | |
| 42 | |
| 43 | def lazy_property(fn): |
| 44 | attr_name = '_lazy_' + fn.__name__ |
| 45 | |
| 46 | lock = threading.Lock() |
| 47 | |
| 48 | @property |
| 49 | def _lazy_property(self): |
| 50 | if hasattr(self, attr_name): |
| 51 | return getattr(self, attr_name) |
| 52 | |
| 53 | with lock: |
| 54 | if not hasattr(self, attr_name): |
| 55 | setattr(self, attr_name, fn(self)) |
| 56 | return getattr(self, attr_name) |
| 57 | |
| 58 | return _lazy_property |
| 59 | |
| 60 | |
| 61 | class classproperty(object): |