Check the code below:
class A(object):
@property
def db(self):
if not getattr(self, '_db', None):
self.__create_db()
return self._db
def __create_db(self):
self._db = 'created db a heavy operation'
a = A()
print(a.db)
print(a.db)
是否在A类线程安全中调用方法db?我的意思是,是否确保两个线程不会最终调用__create_db?