本文整理汇总了Python中swift.common.db.DatabaseBroker.lock方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseBroker.lock方法的具体用法?Python DatabaseBroker.lock怎么用?Python DatabaseBroker.lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.db.DatabaseBroker
的用法示例。
在下文中一共展示了DatabaseBroker.lock方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_lock
# 需要导入模块: from swift.common.db import DatabaseBroker [as 别名]
# 或者: from swift.common.db.DatabaseBroker import lock [as 别名]
def test_lock(self):
broker = DatabaseBroker(os.path.join(self.testdir, '1.db'), timeout=.1)
got_exc = False
try:
with broker.lock():
pass
except Exception:
got_exc = True
self.assert_(got_exc)
def stub(*args, **kwargs):
pass
broker._initialize = stub
broker.initialize(normalize_timestamp('1'))
with broker.lock():
pass
with broker.lock():
pass
broker2 = DatabaseBroker(os.path.join(self.testdir, '1.db'),
timeout=.1)
broker2._initialize = stub
with broker.lock():
got_exc = False
try:
with broker2.lock():
pass
except LockTimeout:
got_exc = True
self.assert_(got_exc)
try:
with broker.lock():
raise Exception('test')
except Exception:
pass
with broker.lock():
pass