How do I get python code to loop every x mins between the times y and z?
Question: This might be incredibly easy but how do I get python code to loop every x
mins between the times y and z?

For example if I wanted my script to run between midnight (00:00) through to
10 pm (22:00) looping every 5 minutes.


Answer: Try the _[sched_ module](http://docs.python.org/2.7/library/sched.html#module-
sched) in the standard library. Here's an example of calling a function once
per second, starting five seconds in the future, and ending ten seconds in the
future:

    
    
    from sched import scheduler
    from time import time, sleep
    
    s = scheduler(time, sleep)
    
    def run_periodically(start, end, interval, func):
        event_time = start
        while event_time < end:
            s.enterabs(event_time, 0, func, ())
            event_time += interval
        s.run()
    
    if __name__ == '__main__':
    
        def say_hello():
            print 'hello'    
    
        run_periodically(time()+5, time()+10, 1, say_hello)
    

Alternatively, you can work with
[threading.Timer](http://docs.python.org/2.7/library/threading.html#threading.Timer),
but you need to do a little more work to get it to start at a given time, run
every five minutes, and stop at a fixed time.

