Re: CPU usage of Python interpreter doing empty while loop under XP
From: Peter Hansen (peter_at_engcorp.com)
Date: 04/27/04
- Next message: Diez B. Roggisch: "Re: Intercepting method calls"
- Previous message: bap: "Re: Problem with PY2EXE and VPython"
- In reply to: Jon Perez: "Re: CPU usage of Python interpreter doing empty while loop under XP"
- Next in thread: Jon Perez: "Re: CPU usage of Python interpreter doing empty while loop under XP"
- Reply: Jon Perez: "Re: CPU usage of Python interpreter doing empty while loop under XP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 27 Apr 2004 14:24:03 -0400
Jon Perez wrote:
> Peter Hansen wrote:
>
>>How does that help your debugging? That will tell us whether
>>sleep(0) is a better alternative, or whether there is really
>>something else you should be doing instead.
>>
>>(I have never had occasion to use "while 1: pass" in Python, ever.)
>
> I'm trying to debug an event-driven framework I wrote myself and
> there are some iffy situations where a quick and dirty way to halt
> execution and view the state of some variables with print is to
> insert a while 1: pass (or sleep(0)).
Good, then what you are really looking for is to get away from the
print statement and learn to use "import pdb; pdb.set_trace()".
This will drop you into a convenient interpreter prompt right in
the frame where it executes (well, one level down, so just type "r"
to return from the set_trace() call to the calling level). From
this prompt you can inspect any variable in your program, execute
code by single-stepping, and so forth.
Very handy, and it completely obsoletes the "while 1: pass" idea. :-)
-Peter
- Next message: Diez B. Roggisch: "Re: Intercepting method calls"
- Previous message: bap: "Re: Problem with PY2EXE and VPython"
- In reply to: Jon Perez: "Re: CPU usage of Python interpreter doing empty while loop under XP"
- Next in thread: Jon Perez: "Re: CPU usage of Python interpreter doing empty while loop under XP"
- Reply: Jon Perez: "Re: CPU usage of Python interpreter doing empty while loop under XP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|