views:

614

answers:

7

I have a Scheduled Task on a WinXP SP2 machine that is set up to run a python script:

Daily

Start time: 12:03 AM

Schedule task daily: every 1 day

Start date: some time in the past

Repeat task: every 5 minutes

Until: Duration 24 hours

Basically, i want the script to run every five minutes, for ever.
My problem is the task runs sometime after 23:47 every night (presumably after 23:55) and does not run after that. What am I doing wrong? Alternatively, is there a different method you can suggest other than using Windows scheduled tasks?

A: 

What version of Windows are you running?

Did you check the "Settings" tab to make sure all of the options are de-selected?

You might also consider a more feature rich scheduler such as System Scheduler from Splinterware Software

meme
ok. "Wake computer to run this task" was selected and "Run for 72 hrs" was selected. I deselected them.
avguchenko
+1  A: 

On the first pane (labeled "Task") do you have "Run only if logged on" unchecked and "Enabled (scheduled task runs at specified time" checked?

I've run python jobs via Windows scheduled task with settings very similar to what you show.

Doug Harris
yep. "Run only if logged on" is unchecked and "Enabled" is checked.
avguchenko
+3  A: 

you can schedule it from another script and kick this off once a day or after each reboot:

#!/usr/bin/env python

import subprocess

interval = 300  # secs

while True:
    p = subprocess.Popen(['pythonw.exe', 'foo.py'])
    time.sleep(interval)

This way you can do sub-minute intervals also.

Corey Goldberg
why do you use subprocess instead of os.popen?
avguchenko
because os.popen is deprecated. see http://docs.python.org/library/subprocess.html
Corey Goldberg
thanks corey, i am using your solution (which i run at startup) to run my script and it is solid (so far).
avguchenko
+1  A: 

Also, for the past year or so I've seen a common bug where Scheduled Tasks on Server 2003 or XP do not run if either of the following checkboxes are on:

  • "Don't start the task if the computer is running on batteries"
  • "Stop the task if battery mode begins"

It seems that Windows gets a little confused if you have a battery (on a laptop) or a UPS (on a server, for example), whether or not your utility power is working.

Also, as a rule I would trim down the time or uncheck the option to "Stop the task if it runs for X minutes" when you're running it so often.

ewall
both of those and "stop the task" were unchecked. what do you mean by "trim down the time?" Set duration to less than 24 hours?
avguchenko
Yeah. Or, better yet, 5 minutes or less. Think about it: if the script were to have some failure and not close within 5 minutes before the next instance, than over the course of a day you could have 480 separate Python processes running, and the Task Scheduler service has to keep track of all of them to know when to kill them.
ewall
+1  A: 

From what I know, Scheduled Tasks is horrible. You should use something with better control like

http://cronw.sourceforge.net/ or any other implementation of cron for Windows.

CraniumRat
+1  A: 

Until: Duration 24 hours

That shuts it off at the end of the first day.

Remove that, see if it keeps going. It should, and you shouldn't need to install Python in the process. :)

Dean J
+1  A: 

At the risk of not answering your question, can I suggest that if what you have to run is important or even critical then Windows task-Scheduler is not the way to run it.

There are so many awful flows when using the task-scheduler. Lets just start with the obvious ones:

There is no logging. There is no way to investigate what happens when things go wrong. There's no way to distribute work across PCs. There's no fault-tolerance. It's Windows only and the interface is crappy.

If any of the above is a problem for you you need something a bit more sophisticated. My suggestion is that you try Hudson, a.k.a. Sun's continuous integration server.

In addition to all of the above it can do cron-style scheduling, with automatic expiry of logs. It can be set to jabber or email on failure and you can even make it auto diagnose what went wrong with your process if you can make it produce some XML output.

Please please, do not use Windows Scheduled tasks. There are many better things to use, and I speak from experience when I say that I never regretted dumping the built-in scheduler.

Salim Fadhley