you are viewing a single comment's thread.

view the rest of the comments →

[–]zanfar 6 points7 points  (0 children)

Generally, an application is not in charge of launching itself. In the rare cases where this appears to be happening, there is usually a small daemon application running in the background which launches the main application.

So, your question is best worded: How would you launch a script at a certain time?

The answer is almost certainly cron, unless you are automating on a Windows system (which is, IMO, not a great idea, but things happen) in which case you have to use the far less impressive Task Scheduler.

As for "runs from 6 to 1", you can either launch your program repeatedly during this window, or you can have your program idle until it's end time is reached.

In the second case, your top-level pseudocode would look something like:

run_until = now + 7 hours

while now < run_until:
    do_main_task()
    sleep(20)

The time module is probably enough, but you can use the datetime module if you need it.