本文整理汇总了Python中transaction.weakset.WeakSet.clear方法的典型用法代码示例。如果您正苦于以下问题:Python WeakSet.clear方法的具体用法?Python WeakSet.clear怎么用?Python WeakSet.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transaction.weakset.WeakSet
的用法示例。
在下文中一共展示了WeakSet.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_clear
# 需要导入模块: from transaction.weakset import WeakSet [as 别名]
# 或者: from transaction.weakset.WeakSet import clear [as 别名]
def test_clear(self):
from transaction.weakset import WeakSet
w = WeakSet()
dummy = Dummy()
w.add(dummy)
dummy2 = Dummy()
w.add(dummy2)
self.assertEqual(dummy in w, True)
self.assertEqual(dummy2 in w, True)
w.clear()
self.assertEqual(dummy in w, False)
self.assertEqual(dummy2 in w, False)
示例2: TransactionManager
# 需要导入模块: from transaction.weakset import WeakSet [as 别名]
# 或者: from transaction.weakset.WeakSet import clear [as 别名]
class TransactionManager(object):
def __init__(self):
self._txn = None
self._synchs = WeakSet()
def begin(self):
""" See ITransactionManager.
"""
if self._txn is not None:
self._txn.abort()
txn = self._txn = Transaction(self._synchs, self)
_new_transaction(txn, self._synchs)
return txn
__enter__ = lambda self: self.begin()
def get(self):
""" See ITransactionManager.
"""
if self._txn is None:
self._txn = Transaction(self._synchs, self)
return self._txn
def free(self, txn):
if txn is not self._txn:
raise ValueError("Foreign transaction")
self._txn = None
def registerSynch(self, synch):
""" See ITransactionManager.
"""
self._synchs.add(synch)
if self._txn is not None:
synch.newTransaction(self._txn)
def unregisterSynch(self, synch):
""" See ITransactionManager.
"""
self._synchs.remove(synch)
def clearSynchs(self):
""" See ITransactionManager.
"""
self._synchs.clear()
def registeredSynchs(self):
""" See ITransactionManager.
"""
return bool(self._synchs)
def isDoomed(self):
""" See ITransactionManager.
"""
return self.get().isDoomed()
def doom(self):
""" See ITransactionManager.
"""
return self.get().doom()
def commit(self):
""" See ITransactionManager.
"""
return self.get().commit()
def abort(self):
""" See ITransactionManager.
"""
return self.get().abort()
def __exit__(self, t, v, tb):
if v is None:
self.commit()
else:
self.abort()
def savepoint(self, optimistic=False):
""" See ITransactionManager.
"""
return self.get().savepoint(optimistic)
def attempts(self, number=3):
if number <= 0:
raise ValueError("number must be positive")
while number:
number -= 1
if number:
yield Attempt(self)
else:
yield self
def _retryable(self, error_type, error):
if issubclass(error_type, TransientError):
return True
for dm in self.get()._resources:
should_retry = getattr(dm, 'should_retry', None)
if (should_retry is not None) and should_retry(error):
return True