frank at chagford.com
Thu Feb 21 06:42:30 CET 2013
On 21/02/2013 06:04, Rita wrote:
> Here is what I am trying to do. (Currently, I am doing this in cron but
> i need much more granularity). I am trying to run program every 20 secs
> and loop forever. I have several of these types of processes, some
> should run every 5 mins, 10 secs, 20 secs, 1 min and so forth. I was
> wondering what is the best way to do this?
> Also, would Greenlet do something I am asking for?
Don't know if this helps, but ...
I have a program with a main loop that listens for input, and
simultaneously I need to run something in the background on a regular
basis. I use the threading module, like this.
self.event = threading.Event()
event = self.event # make local
while not event.is_set():
[run your activity here]
event.wait(10) # check every 10 seconds
Before the main loop starts, I have -
check = Check()
When the main loop ends, I have -
For multiple activities, you could have one class per activity, or have
a generic class, and pass in the executable and the timeout as parameters.
More information about the Python-list