RE: Windows XP - cron or scheduler for Python?

Discussion in 'Python' started by Tim Golden, Jun 24, 2004.

  1. Tim Golden

    Tim Golden Guest

    | I'm trying to have some scripts run periodically on Windows
    | XP and found the "Task Scheduler" did not execute my scripts.
    | My scripts are of the form scriptName.py, and will run just
    | by invoking that name in the Command Prompt.
    |
    | Has anyone used the Windows Task Scheduler to run .py
    | scripts, and if so is there some intracacy to it?
    |
    | Is there a more UNIX version of a cron program one can run on Windows?


    Others have already responded on using the Task Scheduler,
    and maybe you've already set yourself up that way. There
    certainly are cron-like programs on Win32 (and, let's face
    it, it's not hard to write your own). But I'm initially
    very pleased with Irmen de Jong's Kronos from
    http://www.razorvine.net/download/kronos.py.

    As a test, I run the following script -- usually with
    pythonw.exe to avoid an unncessary console window -- and
    it pops up every two minutes with a message box. You can
    obviously do anything you like with the tasks, and you
    have the choice of interval-based or time-of-day-based
    tasks. It wouldn't be at all hard to read the info from
    a crontab-style file at startup (don't know if Irmen's
    already working on anything like that).

    <code>

    import kronos
    import win32ui

    def do_reminder ():
    win32ui.MessageBox ("This is a reminder", "Reminder")

    s = kronos.Scheduler ()
    s.addIntervalTask (
    action = do_reminder,
    taskname = "Reminder",
    initialdelay = 0,
    interval = 120,
    processmethod = s.PM_SEQUENTIAL,
    actionargs = []
    )
    s.start ()
    while 1:
    try:
    try:
    pass
    except KeyboardInterrupt:
    break
    finally:
    s.stop ()

    </code>


    TJG


    ________________________________________________________________________
    This e-mail has been scanned for all viruses by Star Internet. The
    service is powered by MessageLabs. For more information on a proactive
    anti-virus service working around the clock, around the globe, visit:
    http://www.star.net.uk
    ________________________________________________________________________
     
    Tim Golden, Jun 24, 2004
    #1
    1. Advertising

  2. Tim Golden wrote:

    > | I'm trying to have some scripts run periodically on Windows
    > | XP and found the "Task Scheduler" did not execute my scripts.
    > | My scripts are of the form scriptName.py, and will run just
    > | by invoking that name in the Command Prompt.
    > |
    > | Has anyone used the Windows Task Scheduler to run .py
    > | scripts, and if so is there some intracacy to it?
    > |
    > | Is there a more UNIX version of a cron program one can run on Windows?
    >
    >
    > Others have already responded on using the Task Scheduler,
    > and maybe you've already set yourself up that way. There
    > certainly are cron-like programs on Win32 (and, let's face
    > it, it's not hard to write your own). But I'm initially
    > very pleased with Irmen de Jong's Kronos from
    > http://www.razorvine.net/download/kronos.py.


    Thanks for that :) Kronos could use a bit of extra testing.

    Mind you that you will have to have it running to execute
    the tasks you schedule. This is rather obvious, but if the
    original poster wants to run scripts without having to take
    care of this himself, it's a bit of a problem.

    > tasks. It wouldn't be at all hard to read the info from
    > a crontab-style file at startup (don't know if Irmen's
    > already working on anything like that).


    I'm not. Kronos is meant to be an "embedded" scheduler.
    But, as you say, it would be rather trivial to parse a
    config file at startup time, where a bunch of tasks
    are defined.

    Tip: you can use os.system as the task action.... ;-)

    --Irmen
     
    Irmen de Jong, Jun 24, 2004
    #2
    1. Advertising

  3. Tim Golden wrote:

    [...]
    > s.start ()
    > while 1:
    > try:
    > try:
    > pass
    > except KeyboardInterrupt:
    > break
    > finally:
    > s.stop ()


    That's not a very good way of doing that.
    This will eat 100% CPU time, it's a busy wait loop...
    You should use time.sleep or something else to avoid
    busy waiting.
    But since you used the 'regular' Scheduler class from
    Kronos, it will loop inside the s.start() by itself ... ;-)

    --Irmen
     
    Irmen de Jong, Jun 24, 2004
    #3
  4. Tim Golden

    Tim Golden Guest

    Irmen de Jong wrote:
    > Tim Golden wrote:
    >
    > [...]
    >
    >> s.start ()
    >> while 1:
    >> try:
    >> try:
    >> pass
    >> except KeyboardInterrupt:
    >> break
    >> finally:
    >> s.stop ()

    >
    >
    > That's not a very good way of doing that.
    > This will eat 100% CPU time, it's a busy wait loop...
    > You should use time.sleep or something else to avoid
    > busy waiting.
    > But since you used the 'regular' Scheduler class from
    > Kronos, it will loop inside the s.start() by itself ... ;-)
    >
    > --Irmen


    Thanks. For some reason it doesn't actually use
    100% CPU, otherwise I'd have spotted it slowing down
    my machine. I take the point, though. To be honest,
    I was just trying the thing out. Also, I have to
    kick myself for even writing that particular piece
    of code like that.

    TJG
     
    Tim Golden, Jun 25, 2004
    #4
  5. Tim Golden

    Emilio Guest

    Cron clients for Windows to find they are expensive, or have bugs and
    are not stable. So I wrote a very simple yet powerful script that
    handles all the basic functionality of Cron. It has been stable and
    used in production for about a year. The source code is in Python and
    you can read it, it is a simple page. I have also created a version for
    Windows with an installer that doesn't even require Python installed in
    the target machine.

    You can find the project here:
    http://sourceforge.net/projects/pycron

    Emilio.
     
    Emilio, Dec 23, 2004
    #5
    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,536
  2. Christina Robertson

    Windows 2000, scheduler and java

    Christina Robertson, Sep 10, 2003, in forum: Java
    Replies:
    2
    Views:
    1,776
  3. Eric @ Zomething

    Windows XP - cron or scheduler for Python?

    Eric @ Zomething, Jun 20, 2004, in forum: Python
    Replies:
    19
    Views:
    4,632
    Esmail Bonakdarian
    Dec 27, 2004
  4. Allan Palmer

    Interacting with Windows Scheduler

    Allan Palmer, Jun 2, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    138
    ccallen
    Jun 7, 2004
  5. manika02

    WebServices and Windows Scheduler

    manika02, Mar 31, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    148
    manika02
    Mar 31, 2006
Loading...

Share This Page