The sched
module will let you do this. So will the Timer
class in the threading
module.
However, either of those is overkill for what you want.
The easy, and generally best, way to do it is to use your system's scheduler (Scheduled Tasks on Windows, Launch Services on mac, cron
or a related program on most other systems) to run your program every 15 minutes.
Alternatively, just use time.sleep(15*60)
, and check whether time.time()
is actually 15*60 seconds later than last time through the loop.
One advantage of triggering your script from outside is that it makes it very easy to change the trigger. For example, you could change it to trigger every time the file has been modified, instead of every 15 minutes, without changing your script at all. (The exact way you do that, of course, depends on your platform; LaunchServices, famd, inotify, FindFirstChangeNotification, etc. all work very differently. But every modern platform has some way to do it.)