how to run a python script at a specific time in pc | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

how to run a python script at a specific time in pc

guys i ve written a python script on my pc... i want it to run automatically at a specific time...plz tell me how to do it

24th May 2020, 12:14 PM
PRO
PRO - avatar
7 Answers
+ 5
# will execute the inside part at exactly 15:00:00 import datetime while True: t = datetime.datetime.now() if t.hour == 15 and t.minute == 0 and t.second == 0: # Your code here
24th May 2020, 12:27 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
𝕿𝖍𝖊 𝕲𝖗𝖊𝖆𝖙 𝕾𝖆𝖌𝖆 Sure, if it is enough to check every minute, time.sleep(60) will do. Just so it is clear -- the CPU allocation will be minimal. I used to have a simple daily routine checker ran in this way on the "baby Pi" and it worked smoothly :)
24th May 2020, 6:36 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Just put the code inside an infinite while loop and check for the current time with a frequency you need.
24th May 2020, 12:20 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
ohh..thank you Kuba Siekierzyński bro
24th May 2020, 12:29 PM
PRO
PRO - avatar
+ 1
Kuba Siekierzyński The code you have written will keeps CPU busy. Don't you think we can add sleep according to user interest?
24th May 2020, 6:24 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar
0
plz explain it in more detail Kuba Siekierzyński
24th May 2020, 12:21 PM
PRO
PRO - avatar
24th May 2020, 10:48 PM
$¢𝐎₹𝔭!𝐨𝓝
$¢𝐎₹𝔭!𝐨𝓝 - avatar