我有一个基类,@classmethod
它充当许多后代类中大量方法的装饰器。
class BaseClass():
@classmethod
def some_decorator(cls, method):
@wraps(method)
def inner_method(self, *args, **kwargs):
# do stuff
return method(self, *args, **kwargs)
return inner_method
class ChildClass(BaseClass):
@BaseClass.some_decorator
def some_child_method(self):
# do other stuff
return
当我分析此代码并通过树视图查看它时,我看到some_decorator
来自数百个不同地方的数千个调用。
然后我看到some_decorator
回电到数百个它刚刚来自的地方。
这很烦人,我还没有找到解决方法,既不是通过更改代码也不是通过其他方式分析。(使用 gprof2dot atm:How can you get the call tree with python profilers?)
想法?