本文整理匯總了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()))