1

So far, I've learned programming using languages that are interpreted (javascript.) So it's easy enough for me to draw shapes, and do cool things while the user is interacting. But now I want to make a program that does things in the background of the users machine, and doesn't take up a lot of resources. I'm familiar with python, so I've started making key functions, and I can run them from the terminal, but I'm lost on how I could tell the program to check for hard drives, say, every ten minutes.

Is there an OS feature that my program can get called upon every ten minutes? Or should I do a while loop, and just wait for something to change?

The latter seems processesor-heavy, but I have no idea. If you could just give me the keywords to Google, I could follow the rabbit hole, but this isn't something I've ever run across.

Kaninepete
  • 1,357
  • 2
  • 10
  • 12
  • You should really specify which OS you are using. As you stated, you can write a program to behave as a daemon (which is what you refer to as "running in the background indefinitely"), or run periodically using Cron (or the equivalent for your OS). Either of these methods will depend on your OS/environment/toolset. – wkunker Apr 13 '14 at 22:44

2 Answers2

1

If you're on Unix, you can use cron. An example of a crontab entry that runs every ten minutes:

$ crontab -l

*/10 * * * *  /home/username/script.py

Here's an intro to cron: http://www.unixgeeks.org/security/newbie/unix/cron-1.html.


On Windows, use Task Scheduler.

Community
  • 1
  • 1
Qrtn
  • 794
  • 6
  • 17
0

A very easy way to run something every 10 minutes is the following:

import time

while(True):
    yourFunction(...)
    time.sleep(600)

Time.sleep(600) will pause the execution of your program for 600 seconds

papafe
  • 2,959
  • 4
  • 41
  • 72