Python objgraph.show_backrefs() Examples

The following are 8 code examples of objgraph.show_backrefs(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module objgraph , or try the search function .
Example #1
Source File: __init__.py    From qubes-core-admin with GNU Lesser General Public License v2.1 6 votes vote down vote up
def cleanup_gc(self):
        gc.collect()
        leaked = [obj for obj in gc.get_objects() + gc.garbage
                  if isinstance(obj,
                                (qubes.Qubes, qubes.vm.BaseVM,
                                 libvirt.virConnect, libvirt.virDomain))]

        if leaked:
            try:
                import objgraph
                objgraph.show_backrefs(leaked,
                                       max_depth=15, extra_info=extra_info,
                                       filename='/tmp/objgraph-{}.png'.format(
                                           self.id()))
            except ImportError:
                pass

        # do not keep leaked object references in locals()
        leaked = bool(leaked)
        assert not leaked 
Example #2
Source File: conftest.py    From glue-vispy-viewers with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def pytest_runtest_teardown(item, nextitem):

    # The following is a check to make sure that once the viewer and
    # application have been closed, there are no leftover references to data
    # viewers or application. This was introduced because there were
    # previously circular references that meant that viewer instances were
    # not properly garbage collected, which in turn meant they still reacted
    # in some cases to events.

    if OBJGRAPH_INSTALLED and hasattr(item, '_viewer_count'):

        app.processEvents()

        for viewer_cls in VIEWER_CLASSES:

            obj = objgraph.by_type(viewer_cls)

            if len(obj) > item._viewer_count:
                objgraph.show_backrefs(objgraph.by_type(viewer_cls))
                raise ValueError("No net viewers should be created in tests") 
Example #3
Source File: graphing_backreferences.py    From Expert-Python-Programming_Second-Edition with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def example():
    x = []
    y = [x, [x], dict(x=x)]

    objgraph.show_refs(
        (x, y),
        filename='show_refs.png',
        refcounts=True
    )
    objgraph.show_backrefs(
        (x, y),
        filename='show_backrefs.png',
        refcounts=True
    ) 
Example #4
Source File: pickle.py    From kansha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __reduce__(self):
        if objgraph:
            database.session.expire_all()
            objgraph.show_backrefs([self], max_depth=5)

        raise pickle.PicklingError(
            'This object is not picklable: {!r}'.format(self)
        ) 
Example #5
Source File: test_memory.py    From grpclib with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _check(type_name):
    """Utility function to debug references"""
    import objgraph

    objects = objgraph.by_type(type_name)
    if objects:
        obj = objects[0]
        objgraph.show_backrefs(obj, max_depth=3, filename='graph.png') 
Example #6
Source File: test__destruct.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def generate_graphs(target_object_s):
        try:
            import objgraph
        except ImportError:
            print("ImportError no generation of graph")
            return

        print("graph from object: ", target_object_s, id(target_object_s))

        if isinstance(target_object_s, list):
            target_object = target_object_s[0]
            folder_path = os.path.join(testing_utils.RAFCON_TEMP_PATH_TEST_BASE, "..", "..",
                                       target_object.__class__.__name__)
            if os.path.exists(folder_path):
                shutil.rmtree(folder_path)
            for to in set(target_object_s):  # set used to additional avoid multiple identical graph generation
                generate_graphs(to)
        else:
            print("generate graph")
            target_object = target_object_s
            folder_path = os.path.join(testing_utils.RAFCON_TEMP_PATH_TEST_BASE, "..", "..",
                                       target_object.__class__.__name__)
            if not os.path.exists(folder_path):
                os.makedirs(folder_path)
            graph_file_name = os.path.join(folder_path, str(id(target_object)) + "_sample-graph.png")
            objgraph.show_backrefs(target_object,
                                   max_depth=7, extra_ignore=(), filter=None, too_many=10,
                                   highlight=None,
                                   extra_info=None, refcounts=True, shortnames=False,
                                   filename=graph_file_name)
            print("generate graph finished") 
Example #7
Source File: graphing_backreferences.py    From Expert-Python-Programming-Third-Edition with MIT License 5 votes vote down vote up
def graph_references(*objects):
    objgraph.show_refs(
        objects,
        filename='show_refs.png',
        refcounts=True,
        # additional filtering for the sake of brevity
        too_many=5,
        filter=lambda x: not isinstance(x, dict),
    )
    objgraph.show_backrefs(
        objects,
        filename='show_backrefs.png',
        refcounts=True
    ) 
Example #8
Source File: runserver.py    From oio-swift with Apache License 2.0 5 votes vote down vote up
def run_objgraph(types):
    import objgraph
    import os
    import random
    objgraph.show_most_common_types(limit=50, shortnames=False)
    for type_ in types:
        count = objgraph.count(type_)
        print('%s objects: %d' % (type_, count))
        if count:
            objgraph.show_backrefs(
                random.choice(objgraph.by_type(type_)), max_depth=20,
                filename='/tmp/backrefs_%s_%d.dot' % (type_, os.getpid()))