[Tutor] Infinite Loops (and threads)
Kent Johnson
kent37 at tds.net
Sun Dec 24 13:52:05 CET 2006
Jonathan McManus wrote:
> Hi all,
>
> Just a quick question, really. Is there any good way to have an infinite
> loop in a program, without said infinite loop eating up the CPU? I've
> tried the trick of adding a pause (time.sleep(0.01)) somewhere in the
> loop, and this appears to have worked on a basic infinite loop, but this
> doesn't appear to work for two separate infinite loops (in threads).
You would have to put a sleep in each thread.
Why are you using infinite loops? Are you implementing some kind of
polling loop? Often there are better alternatives, either an event
notification or some kind of lock. If you post some details of why you
want to do this we may be able to help you find a better way.
Kent
More information about the Tutor
mailing list