How can I make a program automatically run once per day?

Ian Kelly ian.g.kelly at gmail.com
Thu Jul 14 13:13:57 EDT 2011


On Thu, Jul 14, 2011 at 11:00 AM, monkeys paw <monkey at joemoney.net> wrote:
> You could use the below code. time.sleep(# seconds in a day)
> where i == 30 would run once a day for a month
>
> import time
> i=0
> while (1):
>        print 'hello'
>        time.sleep(2)   # Change this to number of seconds in a day
>        if (i == 3):    # make this 30 for a month
>                break
>        i = i + 1

If the system ever gets rebooted during that month, then you would
need to remember to manually restart the script.  Or if the effective
part of the script raises an exception, it could crash the whole
script without some defensive coding.  That's why it's better just to
use the system scheduler service.



More information about the Python-list mailing list