运行 新线程中的调度函数

Run schedule function in new thread

我使用 schedule 库每隔 X 秒安排一个函数:

我想要的是运行这个函数在单独的线程上。我在关于如何 Run the scheduler in a separate thread 的文档中找到了这个,但我不明白他做了什么。

有没有人可以向我解释如何做到这一点?

更新:

这是我尝试过的:

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()

您真的不需要在每个任务中更新计划

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)