How can I set up starting of python file everyday at same time but after 12hours stop
-
This question isn't unclear, they're asking how to set a python script to run every day at 10pm for 12 hours. Could one of the close voters clarify their confusion? – TankorSmash Jul 03 '16 at 22:19
-
I'm not one of the close voters, but this question could be interpreted as being OS-specific, so at least specifying which OS would be helpful. – Aya Jul 03 '16 at 22:58
2 Answers
Use cron to start at same time every day:
https://help.ubuntu.com/community/CronHowto
In your code, note the time the program starts using datetime.now()
and in the main loop of your program, run until it is 12 hours later

- 4,393
- 6
- 30
- 46
You haven't specified your OS, etc., but here's a general approach:
Step 1: Write a python script that terminates after 12 hours. (Trivial -- see this)
Step 2: If you're using ubuntu, you can create a crontab and then do the following:
~$ crontab -e
Which will then open up a text file named "crontab" in nano, vim, whatever.
Step3: Next, append this line to the crontab so that the script executes everyday at 10PM:
0 22 * * * /usr/bin/python /path/to/script.py
If you've programmed the script correctly, then it should terminate after 12 hours.
Check out this helpful Digital Ocean reference for more details on using crontab.

- 1
- 1

- 109
- 1
- 7