當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。