本文整理汇总了Python中transaction.weakset.WeakSet.map方法的典型用法代码示例。如果您正苦于以下问题:Python WeakSet.map方法的具体用法?Python WeakSet.map怎么用?Python WeakSet.map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类transaction.weakset.WeakSet
的用法示例。
在下文中一共展示了WeakSet.map方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_map_w_gced_element
# 需要导入模块: from transaction.weakset import WeakSet [as 别名]
# 或者: from transaction.weakset.WeakSet import map [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_map
# 需要导入模块: from transaction.weakset import WeakSet [as 别名]
# 或者: from transaction.weakset.WeakSet import map [as 别名]
def test_map(self):
from transaction.weakset import WeakSet
w = WeakSet()
dummy = Dummy()
dummy2 = Dummy()
dummy3 = Dummy()
w.add(dummy)
w.add(dummy2)
w.add(dummy3)
def poker(x):
x.poked = 1
w.map(poker)
for thing in dummy, dummy2, dummy3:
self.assertEqual(thing.poked, 1)