开发者

Creating a Timer to run a program periodically

开发者 https://www.devze.com 2023-04-13 07:49 出处:网络
I\'ve created a program which edits a .txt file. This .tx开发者_开发百科t 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 auto

I've created a program which edits a .txt file. This .tx开发者_开发百科t 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.


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.


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


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

Creating a Timer to run a program periodically

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

Hope this helps!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号