Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #85535

Re: line_profiler: what am I doing wrong?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'cpython': 0.05; 'insert': 0.05; 'url:bitbucket': 0.05; 'pypy': 0.07; 'referring': 0.07; 'skip:` 10': 0.07; 'implemented.': 0.09; 'indeed,': 0.09; 'name?': 0.09; 'namespace': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:pypy': 0.09; 'python': 0.11; '*a*': 0.16; ':-(': 0.16; '__builtin__': 0.16; 'kern': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'sad': 0.16; 'shorten': 0.16; 'tracing': 0.16; 'underlying': 0.16; 'url:py': 0.16; 'wrote:': 0.18; 'else,': 0.19; 'written': 0.21; 'header:User-Agent:1': 0.23; 'interpret': 0.24; "i've": 0.25; 'developers': 0.25; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; "doesn't": 0.30; 'robert': 0.30; 'code': 0.31; 'too.': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'subject:what': 0.31; 'anyone': 0.31; 'run': 0.32; 'url:python': 0.33; 'implemented': 0.33; 'skip:_ 10': 0.34; 'tool': 0.35; 'but': 0.35; 'there': 0.35; 'i.e.': 0.36; 'interface,': 0.36; 'library.': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'implement': 0.38; 'to:addr:python-list': 0.38; 'does': 0.39; 'quote': 0.39; 'supporting': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'helps': 0.61; 'profile': 0.61; 'name': 0.63; 'our': 0.64; 'different': 0.65; 'world': 0.66; 'believe': 0.68; 'production': 0.68; 'detail.': 0.68; 'desperate': 0.84; 'eco': 0.84; 'subject:skip:l 10': 0.84; 'terrible': 0.84; 'profile.': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robert Kern <robert.kern@gmail.com>
Subject Re: line_profiler: what am I doing wrong?
Date Wed, 11 Feb 2015 15:42:27 +0000
References <mailman.18635.1423613207.18130.python-list@python.org> <54daa1d6$0$12979$c3e8da3$5496439d@news.astraweb.com> <mailman.18639.1423615521.18130.python-list@python.org> <54daada4$0$12998$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 213.1.240.226
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:31.0) Gecko/20100101 Thunderbird/31.4.0
In-Reply-To <54daada4$0$12998$c3e8da3$5496439d@news.astraweb.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.18659.1423669372.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1423669372 news.xs4all.nl 2853 [2001:888:2000:d::a6]:37049
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:85535

Show key headers only | View raw


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

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

line_profiler: what am I doing wrong? Neal Becker <ndbecker2@gmail.com> - 2015-02-10 19:06 -0500
  Re: line_profiler: what am I doing wrong? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-11 11:27 +1100
    Re: line_profiler: what am I doing wrong? Neal Becker <ndbecker2@gmail.com> - 2015-02-10 19:45 -0500
      Re: line_profiler: what am I doing wrong? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-11 12:17 +1100
        Re: line_profiler: what am I doing wrong? Robert Kern <robert.kern@gmail.com> - 2015-02-11 15:42 +0000
          Re: line_profiler: what am I doing wrong? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-02-12 10:02 +1100
        Re: line_profiler: what am I doing wrong? Neal Becker <ndbecker2@gmail.com> - 2015-02-13 08:33 -0500

csiph-web