Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provided noop_profile_decorator does not work properly with line_profiler in Python 3 #7

Open
RobertoPrevato opened this issue Apr 17, 2017 · 0 comments

Comments

@RobertoPrevato
Copy link

RobertoPrevato commented Apr 17, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant