Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Python scheduler

Reply
Thread Tools

Re: Python scheduler

 
 
Frank Millman
Guest
Posts: n/a
 
      02-21-2013
On 21/02/2013 06:04, Rita wrote:
> Hello,
>
>
> 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.

import threading

class Check(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.event = threading.Event()

def run(self):
event = self.event # make local
while not event.is_set():
[run your activity here]
event.wait(10) # check every 10 seconds

def stop(self):
self.event.set()

Before the main loop starts, I have -

check = Check()
check.start()

When the main loop ends, I have -

check.stop()
check.join()

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.

HTH

Frank Millman


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dotnet scheduler like the Windows "Schedued Tasks" scheduler? Codemonkey ASP .Net 8 06-10-2011 10:53 AM
Windows XP - cron or scheduler for Python? Eric @ Zomething Python 19 12-27-2004 02:55 AM
RE: Windows XP - cron or scheduler for Python? Tim Golden Python 4 12-23-2004 07:15 PM
python thread scheduler? project2501 Python 2 04-09-2004 05:35 PM
Re: python thread scheduler? Python 1 04-08-2004 08:21 AM



Advertisments