本文整理汇总了Python中objgraph.show_backrefs方法的典型用法代码示例。如果您正苦于以下问题:Python objgraph.show_backrefs方法的具体用法?Python objgraph.show_backrefs怎么用?Python objgraph.show_backrefs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类objgraph
的用法示例。
在下文中一共展示了objgraph.show_backrefs方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cleanup_gc
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_backrefs [as 别名]
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
示例2: pytest_runtest_teardown
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_backrefs [as 别名]
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")
示例3: example
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_backrefs [as 别名]
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
)
开发者ID:PacktPublishing,项目名称:Expert-Python-Programming_Second-Edition,代码行数:16,代码来源:graphing_backreferences.py
示例4: __reduce__
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_backrefs [as 别名]
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)
)
示例5: _check
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_backrefs [as 别名]
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')
示例6: generate_graphs
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_backrefs [as 别名]
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")
示例7: graph_references
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_backrefs [as 别名]
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
)
开发者ID:PacktPublishing,项目名称:Expert-Python-Programming-Third-Edition,代码行数:16,代码来源:graphing_backreferences.py
示例8: run_objgraph
# 需要导入模块: import objgraph [as 别名]
# 或者: from objgraph import show_backrefs [as 别名]
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()))