Тёмный

How To Run A Python Program At A Specific Time 

Taylor's Software
Подписаться 1,1 тыс.
Просмотров 2,3 тыс.
50% 1

In this video I cover how to run a python program or function at a specific time of day. This is useful when trying to call a function or program at a particular time. It has many use cases such as cron jobs.

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 9   
@dereknirenbergmusic
@dereknirenbergmusic 3 месяца назад
Since I've always been warned against "while True" loops, you could make the "while" parameter dependent on the time: while format_time != stop_time: continue print("The times matched") I'm not sure how much memory it takes to look up the time continuously, but since you're only checking the time to the second: from time import sleep while format_time != stop_time: sleep(1) print("The times matched")
@TaylorsSoftware
@TaylorsSoftware 3 месяца назад
Great job! :)
@sh_vayne
@sh_vayne 5 месяцев назад
Very insightful…
@martinkwong5286
@martinkwong5286 2 месяца назад
would appreciate if you could advise how to modify the script if i would like to stop/break the loop at min sec rather than sec. thanks in advance.
@TaylorsSoftware
@TaylorsSoftware 2 месяца назад
You can use the built in "time.sleep(60*minutes)" function at the end of the while loop after the if statement. Where "minutes" will be a variable that contains the amount of minutes you would like the program to check. I hope this has helped. :)
@martinkwong5286
@martinkwong5286 2 месяца назад
@@TaylorsSoftware sorry , i think you i did not write my question clearly. i am interested to stop/break at milliseconds (for example, stop time = 09:09:01.123456 ) rather than by second. hope you can help, thanks again.
@TaylorsSoftware
@TaylorsSoftware 2 месяца назад
I see now. I recommend you use the "datetime" module for microseconds rather than the "time" module, as it has more information. You can import datetime at the top of your program then set format_time = datetime.datetime.now().strftime("%H:%M:%S.%f"). I hope this helped! :)
@martinkwong5286
@martinkwong5286 2 месяца назад
@@TaylorsSoftware Hello again, the script has been modified but won't break at stop time. Do you know if I am missing anything here? Thanks import time import datetime if __name__ == '__main__': stop_time = "20:38:10.100000" while 1: # local_time = datetime.localtime() format_time = datetime.datetime.now().strftime("%H:%M:%S.%f") if(format_time == stop_time): print("Time Matched") break print(format_time,end=" ") print("Loop broke")
@martinkwong5286
@martinkwong5286 2 месяца назад
@@TaylorsSoftware Hello Again,, the script was modified but seems it won't break at stop time. Do you think I missed anything here? Thanks again. import time import datetime if __name__ == '__main__': stop_time = "20:55:00.500000" while 1: # local_time = datetime.localtime() format_time = datetime.datetime.now().strftime("%H:%M:%S.%f") if(format_time == stop_time): print("Time Matched") break print(format_time,end=" ") print("Loop broke")
Далее
How To Use Recursion In Python
8:50
Просмотров 7 тыс.
How To Create Decorator Functions In Python
4:59
Просмотров 8 тыс.
САМАЯ ТУПАЯ СМЕРТЬ / ЧЕРНЕЦ
1:04:43
Cool Parenting Gadget Against Mosquitos! 🦟👶
00:21
Lets Create An API GUI In Python
10:30
Просмотров 1,3 тыс.
How To Use Multiprocessing In Python
5:00
Просмотров 1,2 тыс.
How To Easily Automate Everything With Python
7:26
Просмотров 1 тыс.
How To Read Word Documents In Python
4:50
Просмотров 3,1 тыс.
How To Create An Executable Python Program
3:48
Просмотров 4,6 тыс.
How To Use Bitwise Operators in Python
7:57
How To Compare Files Using Python
3:24
Просмотров 696
How To Use FTP In Python
4:01
Просмотров 1 тыс.
How To Use Ollama's API With Python
5:38
Просмотров 490
How To Use Pandas In Python
6:45
Просмотров 764
САМАЯ ТУПАЯ СМЕРТЬ / ЧЕРНЕЦ
1:04:43