[英]Architecture for a self-running Python script on Mac OSX
I have the following set-up 我有以下设置
All of the above works just fine. 以上所有工作都很好。 But I need to make a change.
但是我需要做出改变。 I need the script to check a web site for a time in the future (that same day) and then come back prior to that time and run itself again.
我需要该脚本在将来的某个时间(同一天)检查一个网站,然后在该时间之前返回并再次运行。 I know how to do the first part (get the time) but I have no clue how to do the second part.
我知道如何做第一部分(花时间),但是我不知道如何去做第二部分。 How do you get a Python script to (1) run itself at a regular time and then (2) run again at some point in the future?
如何使Python脚本能够(1)定期运行自己,然后(2)在将来的某个时间再次运行? The point in the future will change on a regular basis.
未来的时间点将定期更改。 Sometimes it would be as early as 10AM, other times it may be 7PM.
有时可能早于10AM,有时可能是7PM。
Any thoughts on this and pseudo-code are welcome. 欢迎对此和伪代码有任何想法。 Thanks!
谢谢!
You don't need to hard-code anything in - use crontab
to schedule when your script first runs. 您无需在其中进行任何硬编码-使用
crontab
来安排脚本首次运行的时间。 It checks the website for the time it's supposed to run again, then you call time.sleep()
until the task needs to run again. 它会检查网站是否应该再次运行,然后调用
time.sleep()
直到任务需要再次运行。
将变量设置为将来的时间,并在while()循环中进行检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.