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


Python Fiber.array方法代码示例

本文整理汇总了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()
开发者ID:saghul,项目名称:python-fibers,代码行数:38,代码来源:test_gc.py


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