本文整理汇总了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)
示例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]))
示例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]))