Ami*_*oui 6 python schedule python-3.x
我使用调度库每 X 秒调度一个函数:
我想要的是在单独的线程上运行这个函数。我在有关如何在单独的线程中运行调度程序的文档中找到了这一点,但我不明白他做了什么。
有没有人可以向我解释如何做到这一点?
更新:
这是我尝试过的:
def post_to_db_in_new_thread():
schedule.every(15).seconds.do(save_db)
t1 = threading.Thread(target=post_to_db_in_new_thread, args=[])
t1.start()
Run Code Online (Sandbox Code Playgroud)
您实际上不需要更新每个任务中的计划
import threading
import time
import schedule
def run_threaded(job_func):
job_thread = threading.Thread(target=job_func)
job_thread.start()
schedule.every(15).seconds.do(run_threaded, save_db)
while 1:
schedule.run_pending()
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
884 次 |
| 最近记录: |