当前位置: 首页>>代码示例>>Python>>正文


Python WeakSet.clear方法代码示例

本文整理汇总了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)
开发者ID:hughy603,项目名称:pyramid_tutorial,代码行数:14,代码来源:test_weakset.py

示例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
开发者ID:hughy603,项目名称:pyramid_tutorial,代码行数:102,代码来源:_manager.py


注:本文中的transaction.weakset.WeakSet.clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。