high_performance_python icon indicating copy to clipboard operation
high_performance_python copied to clipboard

Provided noop_profile_decorator does not work properly with line_profiler in Python 3

Open RobertoPrevato opened this issue 8 years ago • 0 comments

Hi, The provided solution for "noop-profile" decorator does not work for Robert Kern's kernprof tool: it fails silently in reaching desired objective, as it prevents exceptions, but also prevent line_profiler from collecting information. It does work for memory_profiler module by Fabian Pedregosa and Philippe Gervais.

I use Python 3.5.2

A solution that works for both line_profiler and memory_profiler is:

# memory profile
try:
    @profile
    def dummy():
        pass
except NameError:
    def profile(func):
        def inner(*args, **kwargs):
            return func(*args, **kwargs)
        return inner

Am I missing something?

Update Sorry, after reading again this part of the book, I see that two solutions are described, one for line_profiler and one for memory_profiler (the one in the repository that I linked above is the one for memory_profiler). But still, isn't it better to just catch NameError exceptions, rather than having two implementations?

Kind Regards

RobertoPrevato avatar Apr 17 '17 11:04 RobertoPrevato