本文整理汇总了Python中fibers.Fiber.array方法的典型用法代码示例。如果您正苦于以下问题:Python Fiber.array方法的具体用法?Python Fiber.array怎么用?Python Fiber.array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fibers.Fiber
的用法示例。
在下文中一共展示了Fiber.array方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_finalizer_crash
# 需要导入模块: from fibers import Fiber [as 别名]
# 或者: from fibers.Fiber import array [as 别名]
def test_finalizer_crash(self):
# This test is designed to crash when active greenlets
# are made garbage collectable, until the underlying
# problem is resolved. How does it work:
# - order of object creation is important
# - array is created first, so it is moved to unreachable first
# - we create a cycle between a greenlet and this array
# - we create an object that participates in gc, is only
# referenced by a greenlet, and would corrupt gc lists
# on destruction, the easiest is to use an object with
# a finalizer
# - because array is the first object in unreachable it is
# cleared first, which causes all references to greenlet
# to disappear and causes greenlet to be destroyed, but since
# it is still live it causes a switch during gc, which causes
# an object with finalizer to be destroyed, which causes stack
# corruption and then a crash
class object_with_finalizer(object):
def __del__(self):
pass
array = []
parent = current()
def greenlet_body():
current().object = object_with_finalizer()
try:
parent.switch()
finally:
del current().object
g = Fiber(greenlet_body)
g.array = array
array.append(g)
g.switch()
del array
del g
current()
gc.collect()