Timer events
Grant Edwards
grante at visi.com
Mon May 17 20:24:05 EDT 2004
In article <mailman.31.1084836986.6949.python-list at python.org>, Paul McNett wrote:
>> If I want a function to be called every second, how would I
>> do this? Would I use timer events?
>
> The simplest but least flexible method is real easy:
>
> import time
>
> def myfunc():
> print "myfunc", time.ctime()
>
> while True:
> myfunc()
> time.sleep(1)
Or, if it's important that the frequency error is zero over the
long run:
next = time.time() + 1.0
while True:
time.sleep(next-time.time())
next += 1.0
myfunc()
--
Grant Edwards grante Yow! I'm dressing up in
at an ill-fitting IVY-LEAGUE
visi.com SUIT!! Too late...
More information about the Python-list
mailing list