问题描述
from threading import Timer
def Add():
...some process...
Timer(86400,Add).start() ## 86400 secs in 24 hours.
if __name__ == '__main__':
Add()
"Consuming Kafka Messages and will run continously once started".
代码运行后,将调用Add函数,程序将开始使用kafka消息并持续等待它。我想每24小时调用一次“添加”功能,而不会打扰kafka进程。为此,我尝试了一个threading.timer,但不确定它是否可以工作。
我还有一个问题-是该线程每24小时初始化一次,还是一个线程每24小时才调用一次。
请告知我我做对了,是否可以正常使用,谢谢!!
解决方法
您可以简单地使用一个额外的函数来调用2020-10-13 00:17:17,480 INFO ___FILE_ONLY___ ╔════════════════════════════════════════════════════════════╗
2020-10-13 00:17:17,480 INFO ___FILE_ONLY___ ╠═ Creating backup and activating new installation ═╣
2020-10-13 00:17:17,480 INFO ___FILE_ONLY___ ╚
2020-10-13 00:17:17,480 DEBUG root Attempting to move directory [C:\Users\Ali cem üzüm\AppData\Local\Google\Cloud SDK\google-cloud-sdk] to [C:\Users\Ali cem üzüm\AppData\Local\Google\Cloud SDK\google-cloud-sdk.staging\.install\.backup]
2020-10-13 00:17:17,498 INFO ___FILE_ONLY___ ══════════════════════════════
2020-10-13 00:17:17,498 DEBUG root Attempting to move directory [C:\Users\Ali cem üzüm\AppData\Local\Google\Cloud SDK\google-cloud-sdk.staging] to [C:\Users\Ali cem üzüm\AppData\Local\Google\Cloud SDK\google-cloud-sdk]
2020-10-13 00:17:17,522 INFO ___FILE_ONLY___ ══════════════════════════════
2020-10-13 00:17:17,522 INFO ___FILE_ONLY___ ╝
2020-10-13 00:17:17,609 DEBUG root Updating notification cache...
2020-10-13 00:17:17,609 INFO ___FILE_ONLY___
2020-10-13 00:17:17,612 INFO ___FILE_ONLY___ Performing post processing steps...
2020-10-13 00:17:17,613 DEBUG root Executing command: ['C:\\Users\\ALICEM~1\\AppData\\Local\\Temp\\tmpfffjhsuk\\python\\python.exe','-S','C:\\Users\\Ali cem üzüm\\AppData\\Local\\Google\\Cloud SDK\\google-cloud-sdk\\lib/gcloud.py','components','post-process']
2020-10-13 00:18:41,872 DEBUG ___FILE_ONLY___
2020-10-13 00:18:41,873 DEBUG ___FILE_ONLY___
2020-10-13 00:18:42,044 INFO ___FILE_ONLY___
Update done!
2020-10-13 00:18:42,049 INFO root Display format: "none"
并为您添加计时器,如下所示:
add()