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


Python gc.get_count方法代码示例

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


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

示例1: check

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def check(self):
        #return self.debug_cycles() # uncomment to just debug cycles
        l0, l1, l2 = gc.get_count()
        if self.debug:
            print('gc_check called:', l0, l1, l2)
        if l0 > self.threshold[0]:
            num = gc.collect(0)
            if self.debug:
                print('collecting gen 0, found: %d unreachable' % num)
            if l1 > self.threshold[1]:
                num = gc.collect(1)
                if self.debug:
                    print('collecting gen 1, found: %d unreachable' % num)
                if l2 > self.threshold[2]:
                    num = gc.collect(2)
                    if self.debug:
                        print('collecting gen 2, found: %d unreachable' % num) 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:19,代码来源:garbage_collector.py

示例2: test_del_newclass

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [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

示例3: test_collect_generations

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def test_collect_generations(self):
        gc.collect()
        # This object will "trickle" into generation N + 1 after
        # each call to collect(N)
        x = []
        gc.collect(0)
        # x is now in gen 1
        a, b, c = gc.get_count()
        gc.collect(1)
        # x is now in gen 2
        d, e, f = gc.get_count()
        gc.collect(2)
        # x is now in gen 3
        g, h, i = gc.get_count()
        # We don't check a, d, g since their exact values depends on
        # internal implementation details of the interpreter.
        self.assertEqual((b, c), (1, 0))
        self.assertEqual((e, f), (0, 1))
        self.assertEqual((h, i), (0, 0)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_gc.py

示例4: check

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def check(self):
        """Called by the QTimer periodically in the GUI thread"""
        # return self.debug_cycles() # uncomment to just debug cycles
        lvl0, lvl1, lvl2 = gc.get_count()
        logging.debug("gc_check called: %d, %d, %d", lvl0, lvl1, lvl2)
        if lvl0 > self.threshold[0]:
            num = gc.collect(0)
            logging.debug("collecting gen 0, found: %d unreachable", num)
            if lvl1 > self.threshold[1]:
                num = gc.collect(1)
                logging.debug("collecting gen 1, found: %d unreachable", num)
                if lvl2 > self.threshold[2]:
                    num = gc.collect(2)
                    logging.debug("collecting gen 2, found: %d unreachable",
                                  num) 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:17,代码来源:garbagecollector.py

示例5: test_get_count

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def test_get_count(self):
        # Avoid future allocation of method object
        assertEqual = self._baseAssertEqual
        gc.collect()
        assertEqual(gc.get_count(), (0, 0, 0))
        a = dict()
        # since gc.collect(), we created two objects:
        # the dict, and the tuple returned by get_count()
        assertEqual(gc.get_count(), (2, 0, 0)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_gc.py

示例6: test_collect_generations

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def test_collect_generations(self):
        # Avoid future allocation of method object
        assertEqual = self.assertEqual
        gc.collect()
        a = dict()
        gc.collect(0)
        assertEqual(gc.get_count(), (0, 1, 0))
        gc.collect(1)
        assertEqual(gc.get_count(), (0, 0, 1))
        gc.collect(2)
        assertEqual(gc.get_count(), (0, 0, 0)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_gc.py

示例7: test_get_count

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def test_get_count(self):
        gc.collect()
        a, b, c = gc.get_count()
        x = []
        d, e, f = gc.get_count()
        self.assertEqual((b, c), (0, 0))
        self.assertEqual((e, f), (0, 0))
        # This is less fragile than asserting that a equals 0.
        self.assertLess(a, 5)
        # Between the two calls to get_count(), at least one object was
        # created (the list).
        self.assertGreater(d, a) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:14,代码来源:test_gc.py

示例8: _get_runtime_gc_count

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def _get_runtime_gc_count(self, observer: metrics.ValueObserver) -> None:
        """Observer callback for garbage collection

        Args:
            observer: the observer to update
        """
        gc_count = gc.get_count()
        for index, count in enumerate(gc_count):
            self._runtime_gc_labels["count"] = str(index)
            observer.observe(count, self._runtime_gc_labels) 
开发者ID:open-telemetry,项目名称:opentelemetry-python,代码行数:12,代码来源:__init__.py

示例9: _make_json_response

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def _make_json_response(self, results, healthy):
        if self._show_details:
            body = {
                'detailed': True,
                'python_version': sys.version,
                'now': str(timeutils.utcnow()),
                'platform': platform.platform(),
                'gc': {
                    'counts': gc.get_count(),
                    'threshold': gc.get_threshold(),
                },
            }
            reasons = []
            for result in results:
                reasons.append({
                    'reason': result.reason,
                    'details': result.details or '',
                    'class': reflection.get_class_name(result,
                                                       fully_qualified=False),
                })
            body['reasons'] = reasons
            body['greenthreads'] = self._get_greenstacks()
            body['threads'] = self._get_threadstacks()
        else:
            body = {
                'reasons': [result.reason for result in results],
                'detailed': False,
            }
        return (self._pretty_json_dumps(body), 'application/json') 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:31,代码来源:__init__.py

示例10: _make_html_response

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def _make_html_response(self, results, healthy):
        try:
            hostname = socket.gethostname()
        except socket.error:
            hostname = None
        translated_results = []
        for result in results:
            translated_results.append({
                'details': result.details or '',
                'reason': result.reason,
                'class': reflection.get_class_name(result,
                                                   fully_qualified=False),
            })
        params = {
            'healthy': healthy,
            'hostname': hostname,
            'results': translated_results,
            'detailed': self._show_details,
            'now': str(timeutils.utcnow()),
            'python_version': sys.version,
            'platform': platform.platform(),
            'gc': {
                'counts': gc.get_count(),
                'threshold': gc.get_threshold(),
             },
             'threads': self._get_threadstacks(),
             'greenthreads': self._get_threadstacks(),
        }
        body = _expand_template(self.HTML_RESPONSE_TEMPLATE, params)
        return (body.strip(), 'text/html') 
开发者ID:openstack,项目名称:oslo.middleware,代码行数:32,代码来源:__init__.py

示例11: test_get_count

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def test_get_count():
    gc.collect()
    expect(gc.get_count(), (0, 0, 0), "get_count()")
    a = dict()
    expect(gc.get_count(), (1, 0, 0), "get_count()") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:7,代码来源:test_gc.py

示例12: test_collect_generations

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def test_collect_generations():
    gc.collect()
    a = dict()
    gc.collect(0)
    expect(gc.get_count(), (0, 1, 0), "collect(0)")
    gc.collect(1)
    expect(gc.get_count(), (0, 0, 1), "collect(1)")
    gc.collect(2)
    expect(gc.get_count(), (0, 0, 0), "collect(1)") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:11,代码来源:test_gc.py

示例13: test_all

# 需要导入模块: import gc [as 别名]
# 或者: from gc import get_count [as 别名]
def test_all():
    gc.collect() # Delete 2nd generation garbage
    run_test("lists", test_list)
    run_test("dicts", test_dict)
    run_test("tuples", test_tuple)
    run_test("classes", test_class)
    run_test("new style classes", test_newstyleclass)
    run_test("instances", test_instance)
    run_test("new instances", test_newinstance)
    run_test("methods", test_method)
    run_test("functions", test_function)
    run_test("frames", test_frame)
    run_test("finalizers", test_finalizer)
    run_test("finalizers (new class)", test_finalizer_newclass)
    run_test("__del__", test_del)
    run_test("__del__ (new class)", test_del_newclass)
    run_test("get_count()", test_get_count)
    run_test("collect(n)", test_collect_generations)
    run_test("saveall", test_saveall)
    run_test("trashcan", test_trashcan)
    run_test("boom", test_boom)
    run_test("boom2", test_boom2)
    run_test("boom_new", test_boom_new)
    run_test("boom2_new", test_boom2_new)
    run_test("get_referents", test_get_referents)
    run_test("bug1055820b", test_bug1055820b)

    gc.enable()
    try:
        run_test("bug1055820c", test_bug1055820c)
    finally:
        gc.disable()

    gc.enable()
    try:
        run_test("bug1055820d", test_bug1055820d)
    finally:
        gc.disable() 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:40,代码来源:test_gc.py


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