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