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


Python gc.set_threshold方法代码示例

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


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

示例1: check_gc_during_creation

# 需要导入模块: import gc [as 别名]
# 或者: from gc import set_threshold [as 别名]
def check_gc_during_creation(self, makeref):
        thresholds = gc.get_threshold()
        gc.set_threshold(1, 1, 1)
        gc.collect()
        class A:
            pass

        def callback(*args):
            pass

        referenced = A()

        a = A()
        a.a = a
        a.wr = makeref(referenced)

        try:
            # now make sure the object and the ref get labeled as
            # cyclic trash:
            a = A()
            weakref.ref(referenced, callback)

        finally:
            gc.set_threshold(*thresholds) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_weakref.py

示例2: test_len_race

# 需要导入模块: import gc [as 别名]
# 或者: from gc import set_threshold [as 别名]
def test_len_race(self):
        # Extended sanity checks for len() in the face of cyclic collection
        self.addCleanup(gc.set_threshold, *gc.get_threshold())
        for th in range(1, 100):
            N = 20
            gc.collect(0)
            gc.set_threshold(th, th, th)
            items = [RefCycle() for i in range(N)]
            s = WeakSet(items)
            del items
            # All items will be collected at next garbage collection pass
            it = iter(s)
            try:
                next(it)
            except StopIteration:
                pass
            n1 = len(s)
            del it
            n2 = len(s)
            self.assertGreaterEqual(n1, 0)
            self.assertLessEqual(n1, N)
            self.assertGreaterEqual(n2, 0)
            self.assertLessEqual(n2, n1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_weakset.py

示例3: test_del_newclass

# 需要导入模块: import gc [as 别名]
# 或者: from gc import set_threshold [as 别名]
def test_del_newclass(self):
        # __del__ methods can trigger collection, make this to happen
        thresholds = gc.get_threshold()
        gc.enable()
        gc.set_threshold(1)

        class A(object):
            def __del__(self):
                dir(self)
        a = A()
        del a

        gc.disable()
        gc.set_threshold(*thresholds)

    # The following two tests are fragile:
    # They precisely count the number of allocations,
    # which is highly implementation-dependent.
    # For example:
    # - disposed tuples are not freed, but reused
    # - the call to assertEqual somehow avoids building its args tuple 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_gc.py

示例4: check_len_race

# 需要导入模块: import gc [as 别名]
# 或者: from gc import set_threshold [as 别名]
def check_len_race(self, dict_type, cons):
        # Extended sanity checks for len() in the face of cyclic collection
        self.addCleanup(gc.set_threshold, *gc.get_threshold())
        for th in range(1, 100):
            N = 20
            gc.collect(0)
            gc.set_threshold(th, th, th)
            items = [RefCycle() for i in range(N)]
            dct = dict_type(cons(o) for o in items)
            del items
            # All items will be collected at next garbage collection pass
            it = dct.iteritems()
            try:
                next(it)
            except StopIteration:
                pass
            n1 = len(dct)
            del it
            n2 = len(dct)
            self.assertGreaterEqual(n1, 0)
            self.assertLessEqual(n1, N)
            self.assertGreaterEqual(n2, 0)
            self.assertLessEqual(n2, n1) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_weakref.py

示例5: test_del_newclass

# 需要导入模块: import gc [as 别名]
# 或者: from gc import set_threshold [as 别名]
def test_del_newclass(self):
        # __del__ methods can trigger collection, make this to happen
        thresholds = gc.get_threshold()
        gc.enable()
        gc.set_threshold(1)

        class A(object):
            def __del__(self):
                dir(self)
        a = A()
        del a

        gc.disable()
        gc.set_threshold(*thresholds)

    # The following two tests are fragile:
    # They precisely count the number of allocations,
    # which is highly implementation-dependent.
    # For example, disposed tuples are not freed, but reused.
    # To minimize variations, though, we first store the get_count() results
    # and check them at the end. 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_gc.py

示例6: check_len_race

# 需要导入模块: import gc [as 别名]
# 或者: from gc import set_threshold [as 别名]
def check_len_race(self, dict_type, cons):
        # Extended sanity checks for len() in the face of cyclic collection
        self.addCleanup(gc.set_threshold, *gc.get_threshold())
        for th in range(1, 100):
            N = 20
            gc.collect(0)
            gc.set_threshold(th, th, th)
            items = [RefCycle() for i in range(N)]
            dct = dict_type(cons(o) for o in items)
            del items
            # All items will be collected at next garbage collection pass
            it = dct.items()
            try:
                next(it)
            except StopIteration:
                pass
            n1 = len(dct)
            del it
            n2 = len(dct)
            self.assertGreaterEqual(n1, 0)
            self.assertLessEqual(n1, N)
            self.assertGreaterEqual(n2, 0)
            self.assertLessEqual(n2, n1) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:25,代码来源:test_weakref.py

示例7: test_threshold

# 需要导入模块: import gc [as 别名]
# 或者: from gc import set_threshold [as 别名]
def test_threshold(self):
        """test 'gci threshold'."""
        g1, g2, g3 = gc.get_threshold()

        output = self.run_command("gci threshold", exitcode=0)
        self.assertIn("G1: " + str(g1), output)
        self.assertIn("G2: " + str(g2), output)
        self.assertIn("G3: " + str(g3), output)

        n1 = g1 + 1
        n2 = g2 + 1
        n3 = g3 + 1
        output = self.run_command("gci threshold {} {} {}".format(n1, n2, n3), exitcode=0)
        self.assertEqual(output.replace("\n", ""), "")

        output = self.run_command("gci threshold", exitcode=0)
        self.assertIn("G1: " + str(n1), output)
        self.assertIn("G2: " + str(n2), output)
        self.assertIn("G3: " + str(n3), output)

        gc.set_threshold(g1, g2, g3)
        output = self.run_command("gci threshold", exitcode=0)
        self.assertIn("G1: " + str(g1), output)
        self.assertIn("G2: " + str(g2), output)
        self.assertIn("G3: " + str(g3), output) 
开发者ID:ywangd,项目名称:stash,代码行数:27,代码来源:test_gci.py

示例8: test_free_from_gc

# 需要导入模块: import gc [as 别名]
# 或者: from gc import set_threshold [as 别名]
def test_free_from_gc(self):
        # Check that freeing of blocks by the garbage collector doesn't deadlock
        # (issue #12352).
        # Make sure the GC is enabled, and set lower collection thresholds to
        # make collections more frequent (and increase the probability of
        # deadlock).
        if not gc.isenabled():
            gc.enable()
            self.addCleanup(gc.disable)
        thresholds = gc.get_threshold()
        self.addCleanup(gc.set_threshold, *thresholds)
        gc.set_threshold(10)

        # perform numerous block allocations, with cyclic references to make
        # sure objects are collected asynchronously by the gc
        for i in range(5000):
            a = multiprocessing.heap.BufferWrapper(1)
            b = multiprocessing.heap.BufferWrapper(1)
            # circular references
            a.buddy = b
            b.buddy = a

#
#
# 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:27,代码来源:_test_multiprocessing.py


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