【问题标题】:PyCallGraph's GlobbingFilter does not work?PyCallGraph 的 GlobbingFilter 不起作用?
【发布时间】:2022-02-03 02:08:56
【问题描述】:

我正在使用 pycallgraph(来自 jupyter notebook)来了解我正在处理的代码库。出于某种原因,GlobbingFilter 似乎不起作用 - 我无法使用 GlobbingFilter 排除事物

from pycallgraph import PyCallGraph, Config, GlobbingFilter
from pycallgraph.output import GraphvizOutput
from PIL import Image
import numpy as np

gv = GraphvizOutput()
gv.output_file = 'basic2.png'

config = Config()
config.trace_filter = GlobbingFilter(
    exclude=['pycallgraph.*', '*__init__*'], include=['__main__'])

class Apple:
    def __init__(self):
        pass 
    
    def eat(self):
        pass

class Basket:
    def __init__(self):
        self.content = []
    
    def add(self, other):
        self.content.append(other)
    
with PyCallGraph(output=gv, config=config):
    a = Apple()
    b = Basket()
    b.add(a)
    b.content[0].eat()
    
Image.open(gv.output_file)

输出图像包含__init__ 方法。关于如何删除它们的任何想法?另外我也不能排除类和他们的孩子(例如Apple

附言。我正在使用callgraph4py(如果pycallgraph,则为托管叉子)

【问题讨论】:

    标签: python graphviz pycallgraph


    【解决方案1】:

    这是一个简单的修复 - 如果我安装的库的版本将 GlobbingFilter 功能注释掉了。

    请参见此处的第 208 行:https://github.com/e-alizadeh/pycallgraph/blob/master/pycallgraph/tracer.py

    取消注释第 208 和 209 行解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2013-12-18
      • 2014-12-09
      • 2022-10-19
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 2019-06-13
      相关资源
      最近更新 更多