CPU usage of Python interpreter doing empty while loop under XP

Peter Hansen peter at engcorp.com
Tue Apr 27 07:33:23 EDT 2004


Jon Perez wrote:

> Dennis Lee Bieber wrote:
> 
>>Stick a sleep(0) inside it, and no doubt you will see performance 
>>return to "normal". Even though the 0 means no actual delay is wanted, 
>>the task swap will occur, giving the OS a chance to respond to events.
> 
> 
> Great, it worked.
> 
> So 
> 
> while 1: sleep(0)
> 
> is a better alternative to
> 
> while 1: pass
> 
> (I'm using this for debugging purposes...)

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.)

-Peter



More information about the Python-list mailing list