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


Python WeakSet.as_weakref_list方法代码示例

本文整理汇总了Python中transaction.weakset.WeakSet.as_weakref_list方法的典型用法代码示例。如果您正苦于以下问题:Python WeakSet.as_weakref_list方法的具体用法?Python WeakSet.as_weakref_list怎么用?Python WeakSet.as_weakref_list使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在transaction.weakset.WeakSet的用法示例。


在下文中一共展示了WeakSet.as_weakref_list方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_map_w_gced_element

# 需要导入模块: from transaction.weakset import WeakSet [as 别名]
# 或者: from transaction.weakset.WeakSet import as_weakref_list [as 别名]
    def test_map_w_gced_element(self):
        import gc
        from transaction.weakset import WeakSet
        w = WeakSet()
        dummy = Dummy()
        dummy2 = Dummy()
        dummy3 = [Dummy()]
        w.add(dummy)
        w.add(dummy2)
        w.add(dummy3[0])

        _orig = w.as_weakref_list
        def _as_weakref_list():
            # simulate race condition during iteration of list
            # object is collected after being iterated.
            result = _orig()
            del dummy3[:]
            gc.collect()
            return result
        w.as_weakref_list = _as_weakref_list

        def poker(x):
            x.poked = 1
        w.map(poker)
        for thing in dummy, dummy2:
            self.assertEqual(thing.poked, 1)
开发者ID:hughy603,项目名称:pyramid_tutorial,代码行数:28,代码来源:test_weakset.py

示例2: test_as_weakref_list

# 需要导入模块: from transaction.weakset import WeakSet [as 别名]
# 或者: from transaction.weakset.WeakSet import as_weakref_list [as 别名]
 def test_as_weakref_list(self):
     w = WeakSet()
     dummy = Dummy()
     dummy2 = Dummy()
     dummy3 = Dummy()
     w.add(dummy)
     w.add(dummy2)
     w.add(dummy3)
     del dummy3
     L = [x() for x in w.as_weakref_list()]
     # L is a list, but it does not have a guaranteed order.
     self.assertTrue(list, type(L))
     self.assertEqual(set(L), set([dummy, dummy2]))
开发者ID:c0ns0le,项目名称:zenoss-4,代码行数:15,代码来源:test_weakset.py

示例3: test_as_weakref_list

# 需要导入模块: from transaction.weakset import WeakSet [as 别名]
# 或者: from transaction.weakset.WeakSet import as_weakref_list [as 别名]
 def test_as_weakref_list(self):
     import gc
     from transaction.weakset import WeakSet
     w = WeakSet()
     dummy = Dummy()
     dummy2 = Dummy()
     dummy3 = Dummy()
     w.add(dummy)
     w.add(dummy2)
     w.add(dummy3)
     del dummy3
     gc.collect()
     L = [x() for x in w.as_weakref_list()]
     # L is a list, but it does not have a guaranteed order.
     self.assertTrue(list, type(L))
     self.assertEqual(set(L), set([dummy, dummy2]))
开发者ID:serg0987,项目名称:python,代码行数:18,代码来源:test_weakset.py


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