Python在指定的时间定期运行类函数

问题描述

我有一个python 3类,其中线程启动该类的功能之一。在此线程中,我尝试在给定间隔timedelta(minues=myinterval)的特定时间运行此功能

例如,假设当前时间是10:17:30 AM,并且该函数需要在当前时间的分钟可以除以00:10:00(即10分钟)的时间运行,即{ {1}}。因此,该功能应首先等待00:02:30,然后在10:20:00 AM、10:30:00AM、10:40:00AM、10:50:00AM等运行timedetla(minutes=10)my_function在线程内启动。

my_function

我使用了以下内容,但似乎不太准确。

class myclass():
...

def my_function():
    print(datetime.Now())

有人可以让我知道更好的方法吗?我希望def run_my_function_at_specified_times(): t = threading.Timer(calculated_wait_time,self.my_function) while True: t.cancel() t.start() 在指定的时间急剧运行。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)