line_profiler: what am I doing wrong?

Neal Becker ndbecker2 at gmail.com
Fri Feb 13 08:33:15 EST 2015


Robert Kern wrote:

> On 2015-02-11 01:17, Steven D'Aprano wrote:
>> Neal Becker wrote:
>>
>>
>>> To quote from https://pypi.python.org/pypi/line_profiler/
>>>
>>> $ kernprof -l script_to_profile.py
>>> kernprof will create an instance of LineProfiler and insert it into the
>>> __builtins__ namespace with the name profile.
>>
>> Ewww!!!! What a Ruby-esque interface, that makes me sad :-(
> 
> <shrug> This is not a production library. It's a development tool designed to
> help developers shorten the cycle time for investigating these kinds of
> issues. Well, *a* developer; i.e. me. If it helps anyone else, yahtzee!
> 
>> And what if you
>> have your own profile global name?
> 
> Then you can pull it out from __builtin__ with a different name and use that
> other name.
> 
>> And *wrong* too. `__builtins__` is a private CPython implementation detail.
>> The way to monkey-patch the built-ins in Python 2 is to inject the object
>> into `__builtin__` (no s), or `builtins` in Python 3.
> 
> And indeed that is how it is implemented. Referring to that namespace as the
> "`__builtins__` namespace" isn't *wrong*. It may mislead you into thinking
> I've implemented it one particular way, if you are desperate to find a nit to
> pick.
> 
>> Seeing as
>> line_profiler is written in C, perhaps the author (Robert Kern) doesn't
>> care about supporting Jython or IronPython,  but there may be Python
>> implementations (PyPy perhaps?) which can run C code but don't have
>> __builtins__.
> 
> Indeed, I do not care about any of them. PyPy does not implement CPython's
> tracing API:
> 
> 
https://bitbucket.org/pypy/pypy/src/2b2163d65ee437646194a1ceb2a3153db24c5f7e/pypy/module/cpyext/stubs.py?at=default#cl-1286
> 

Hi Robert, any idea why line_profiler is not working?  I've used it fine in the 
past.

-- 
-- Those who don't understand recursion are doomed to repeat it




More information about the Python-list mailing list