How to launch a function at regular time intervals ?
Bartosz Wroblewski
user at tld.invalid
Wed Aug 12 18:07:23 EDT 2009
On Wed, 12 Aug 2009 14:09:29 -0700, David wrote:
>
> Hi all, I'm trying to launch a function at regular time intervals but
> cannot find the way to do it.
>
For what it's worth, here's how I do it:
---------------8<---------------
#!/usr/bin/env python
from time import sleep
interval = 25 #seconds
while not sleep(interval):
f(spam, eggs, knight)
---------------8<---------------
You might want to put the sleep inside an *obviously* infinite loop. Note
that this works best (most accurately) for longer periods. If you need to
account for the time spent in the actual f() calls, plug in a time.time()
call where appropriate.
--
| <")-, | ''The good-enough is the enemy of the excellent.'' - John Miles
| (_==/ |-----------,-----------------------------------------------------
| ='- | Bartosz Wroblewski | bawr from holyhandgrenade.info or int8.org
More information about the Python-list
mailing list