stupid line_profiler question

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

stupid line_profiler question

Jonathan Blakes
For some reason I can't get Python to see the @profile decorator of
line_profiler.

This:

import line_profiler
class Polling(HasTraits):
     #...
     @profile
     def _poll_process(self):
         self.process.poll()

Fails with this:

Traceback (most recent call last):
   File "/home/jvb/polling.py", line 12, in <module>
     class PollingHasTraits):
   File "/home/jvb/polling.py", line 35, in Polling
     @profile
NameError: name 'profile' is not defined

How do I get the profile decorator to be defined?

Thankx

Jon
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: stupid line_profiler question

Robert Kern
On Thu, Mar 4, 2010 at 11:58 AM, Jonathan Blakes <[hidden email]> wrote:

> For some reason I can't get Python to see the @profile decorator of
> line_profiler.
>
> This:
>
> import line_profiler
> class Polling(HasTraits):
>     #...
>     @profile
>     def _poll_process(self):
>         self.process.poll()
>
> Fails with this:
>
> Traceback (most recent call last):
>   File "/home/jvb/polling.py", line 12, in <module>
>     class PollingHasTraits):
>   File "/home/jvb/polling.py", line 35, in Polling
>     @profile
> NameError: name 'profile' is not defined
>
> How do I get the profile decorator to be defined?

Use "kernprof -l polling.py" to run your script.

--
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
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: stupid line_profiler question

Jonathan Blakes
In reply to this post by Jonathan Blakes
Jonathan Blakes wrote:

> From:    Robert Kern ([hidden email])
> List:    com.enthought.mail.enthought-dev
> On Thu, Mar 4, 2010 at 11:58 AM, Jonathan Blakes <[hidden email]>
> wrote:
> For some reason I can't get Python to see the @profile decorator of
> line_profiler.
>
> This:
>
> import line_profiler
> class Polling(HasTraits):
>     #...
>     @profile
>     def _poll_process(self):
>         self.process.poll()
>
> Fails with this:
>
> Traceback (most recent call last):
>   File "/home/jvb/polling.py", line 12, in <module>
>     class PollingHasTraits):
>   File "/home/jvb/polling.py", line 35, in Polling
>     @profile
> NameError: name 'profile' is not defined
>
> How do I get the profile decorator to be defined?
>
> Use "kernprof -l polling.py" to run your script.

That's ace Robert. I have created a script to do it for me:

#!/bin/sh
echo "have you remembered to @profile decorate your functions?"
kernprof.py -l -v $1 > $1.lprof.txt
less $1.lprof.txt

line_prof (kernprof) and grin are brilliant tools. Thanks for making them!
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev