Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 为每小时计划一个任务调度器,如果任务未完成,请等待_Python 3.x_Multithreading_Apscheduler - Fatal编程技术网

Python 3.x 为每小时计划一个任务调度器,如果任务未完成,请等待

Python 3.x 为每小时计划一个任务调度器,如果任务未完成,请等待,python-3.x,multithreading,apscheduler,Python 3.x,Multithreading,Apscheduler,我正试图安排每小时运行一个任务。任务是一个执行时间越来越长的函数。功能所需的最小中断时间为从开始的一小时 一旦功能启动,应启动一小时时钟,以便再次启动。随之而来的是一个问题。由于函数越来越长,完成该函数可能需要一个多小时。这意味着调度程序将在函数完成之前调用该函数。我们的目标是从函数开始时起每小时启动一次,但要等到它开始运行时才完成,这需要一个多小时 这就是我一直在尝试的: from threading import Thread from apscheduler.schedulers.bloc

我正试图安排每小时运行一个任务。任务是一个执行时间越来越长的函数。功能所需的最小中断时间为从开始的一小时

一旦功能启动,应启动一小时时钟,以便再次启动。随之而来的是一个问题。由于函数越来越长,完成该函数可能需要一个多小时。这意味着调度程序将在函数完成之前调用该函数。我们的目标是从函数开始时起每小时启动一次,但要等到它开始运行时才完成,这需要一个多小时

这就是我一直在尝试的:

from threading import Thread
from apscheduler.schedulers.blocking import BlockingScheduler
import threading
import time

def job():
    # This is a function that takes longer
    # and longer
    # and longer
    # to complete

thread = Thread(target = job)
scheduler = BlockingScheduler()
scheduler.add_job(job, 'interval', hours=1)

if thread.is_alive():
    print("waiting")
else:
    scheduler.start()