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


Python support.disable_gc方法代码示例

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


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

示例1: collect_in_thread

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import disable_gc [as 别名]
def collect_in_thread(period=0.0001):
    """
    Ensure GC collections happen in a different thread, at a high frequency.
    """
    threading = support.import_module('threading')
    please_stop = False

    def collect():
        while not please_stop:
            time.sleep(period)
            gc.collect()

    with support.disable_gc():
        t = threading.Thread(target=collect)
        t.start()
        try:
            yield
        finally:
            please_stop = True
            t.join() 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:22,代码来源:test_weakref.py

示例2: testNoCycles

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import disable_gc [as 别名]
def testNoCycles(self):
        case = unittest.TestCase()
        wr = weakref.ref(case)
        with support.disable_gc():
            del case
            self.assertFalse(wr()) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:8,代码来源:test_case.py

示例3: test

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import disable_gc [as 别名]
def test(cls):
        """
        A context manager to use around all finalization tests.
        """
        with support.disable_gc():
            cls.del_calls.clear()
            cls.tp_del_calls.clear()
            NonGCSimpleBase._cleaning = False
            try:
                yield
                if cls.errors:
                    raise cls.errors[0]
            finally:
                NonGCSimpleBase._cleaning = True
                cls._cleanup() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:17,代码来源:test_finalization.py

示例4: test_clear_refcycles

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import disable_gc [as 别名]
def test_clear_refcycles(self):
        # .clear() doesn't leave any refcycle behind
        with support.disable_gc():
            class C:
                pass
            c = C()
            wr = weakref.ref(c)
            exc = self.outer(c=c)
            del c
            self.assertIsNot(None, wr())
            self.clear_traceback_frames(exc.__traceback__)
            self.assertIs(None, wr()) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_frame.py

示例5: test_close_with_cleared_frame

# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import disable_gc [as 别名]
def test_close_with_cleared_frame(self):
        # See issue #17669.
        #
        # Create a stack of generators: outer() delegating to inner()
        # delegating to innermost(). The key point is that the instance of
        # inner is created first: this ensures that its frame appears before
        # the instance of outer in the GC linked list.
        #
        # At the gc.collect call:
        #   - frame_clear is called on the inner_gen frame.
        #   - gen_dealloc is called on the outer_gen generator (the only
        #     reference is in the frame's locals).
        #   - gen_close is called on the outer_gen generator.
        #   - gen_close_iter is called to close the inner_gen generator, which
        #     in turn calls gen_close, and gen_yf.
        #
        # Previously, gen_yf would crash since inner_gen's frame had been
        # cleared (and in particular f_stacktop was NULL).

        def innermost():
            yield
        def inner():
            outer_gen = yield
            yield from innermost()
        def outer():
            inner_gen = yield
            yield from inner_gen

        with disable_gc():
            inner_gen = inner()
            outer_gen = outer()
            outer_gen.send(None)
            outer_gen.send(inner_gen)
            outer_gen.send(outer_gen)

            del outer_gen
            del inner_gen
            gc_collect() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:40,代码来源:test_pep380.py


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