Re: Python scheduler

Discussion in 'Python' started by Frank Millman, Feb 21, 2013.

  1. 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
    Frank Millman, Feb 21, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Codemonkey
    Replies:
    8
    Views:
    9,527
  2. project2501

    python thread scheduler?

    project2501, Apr 7, 2004, in forum: Python
    Replies:
    2
    Views:
    367
  3. Guest

    Re: python thread scheduler?

    Guest, Apr 7, 2004, in forum: Python
    Replies:
    1
    Views:
    422
    project2501
    Apr 8, 2004
  4. Eric @ Zomething

    Windows XP - cron or scheduler for Python?

    Eric @ Zomething, Jun 20, 2004, in forum: Python
    Replies:
    19
    Views:
    4,623
    Esmail Bonakdarian
    Dec 27, 2004
  5. Tim Golden
    Replies:
    4
    Views:
    558
    Emilio
    Dec 23, 2004
Loading...

Share This Page