Timed events

Peter Hansen peter at engcorp.com
Fri Jan 31 20:49:10 EST 2003


Sam Marrocco wrote:
> 
> I'm trying to Python a script that will perform a function every few
> seconds. Is there a particularly efficient way to do this that won't hog
> processor time?

The poor man's version is just to use time.sleep().  It doesn't
hog CPU when in that call.

import time
while 1:
    if exitConditionTrue:
        break
    performAFunction()
    time.sleep(3)


-Peter




More information about the Python-list mailing list