Creating a Timer to run a program periodically

I've created a program which edits a .txt file. This .txt file is used as a source of data for our website. These data change every hour. So, how can I make the python program run automatically every hour? I'm just a beginner, sorry.

Upvotes: 2

Views: 6635

Answers (4)

techdude
techdude

Reputation: 1334

On Windows you can use Task Scheduler. Unfortunately, it's not immediately obvious how to create a task that repeats with a time period since it is normally used to schedule things by a time of day, date, day of week, or system state. Here are the instructions to set up a periodic task.

  1. Create a new task. Here you can put the command to run, whether that is an executable, batch file, or other command.
  2. Open the new task's properties.
  3. Go to the Triggers tab
  4. Add a new Trigger
  5. Set when you want the task to first run ("At log on" is a good idea if it needs an interactive user).
  6. If you want it wait a bit, you can specify a delay in minutes
  7. Check "Repeat task every:"
  8. In the drop down, you can select some values, or type your own. Note that on most versions of windows, you can only specify it in terms or minutes, hours, or days. The range of allowed values is between 1 minute and 31 days.
  9. Set the duration (Indefinitely if you want it to run as long as the computer is on.
  10. Click OK

Task Scheduler New Trigger Dialog

Congrats! You can poke around the other settings to see things like how it will handle task failures and other things.

Hope this helps!

Upvotes: 1

Shawn Bower
Shawn Bower

Reputation: 1147

If its windows

Windows Task Scheduler

For command-line usage, you can schedule with the at command. I'll add the schtasks command which is the replacement in newer MS OS.

If its unix base then you can use cron.

Upvotes: 4

Bala
Bala

Reputation: 4547

For Linux and Unix, use crontab command to schedule your Python script.

http://www.computerhope.com/unix/ucrontab.htm

For Windows, use "Scheduled Task"

http://drupal.org/node/31506

Upvotes: 2

mitchellhislop
mitchellhislop

Reputation: 445

The best way is with a cron job - It is a unix system that is made for running scripts at certain times.

Check out http://en.wikipedia.org/wiki/Cron for more information. Hourly is a pretty easy one to set up.

This way, all your program does is the logic (updating the txt file), and you dont need to write the hourly code.

Upvotes: 0

Related Questions