Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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计划,并行执行任务_Python_Schedule - Fatal编程技术网

Python计划,并行执行任务

Python计划,并行执行任务,python,schedule,Python,Schedule,我已使用以下工具安排了我的任务: channel\u crawler运行约需5分钟,而distance\u fixer运行约需5小时。当我在运行距离修正器时运行代码时,计划不会每隔10分钟运行频道爬虫。如何并行运行函数?您可以对作业使用多处理,因此每个进程运行每个函数 def run_schedule(): while True: schedule.run_pending() time.sleep(1) def run_crawler_schedule(

我已使用以下工具安排了我的任务:


channel\u crawler
运行约需
5分钟
,而
distance\u fixer
运行约需
5小时
。当我在运行
距离修正器时运行代码时,计划不会每隔
10分钟运行
频道爬虫
。如何并行运行函数?

您可以对作业使用多处理,因此每个进程运行每个函数

def run_schedule():
    while True:
        schedule.run_pending()
        time.sleep(1)

def run_crawler_schedule():
    channel_crawler(priority=1)
    schedule.every(PRIORITY[1]["interval"]).minutes.do(channel_crawler, priority=1)
    run_schedule(schedule)

def run_fix():
    schedule.every().day.at("17:30").do(distance_fixer)
    run_schedule()


def run_job()
    p = Process(target=run_crawler_schedule)
    c = Process(target=run_fix)
    p.start()
    c.start()
    p.join()
    c.join()

if __name__ == "__main__":
    run_job()

您可以对作业使用多处理,以便每个进程运行每个函数

def run_schedule():
    while True:
        schedule.run_pending()
        time.sleep(1)

def run_crawler_schedule():
    channel_crawler(priority=1)
    schedule.every(PRIORITY[1]["interval"]).minutes.do(channel_crawler, priority=1)
    run_schedule(schedule)

def run_fix():
    schedule.every().day.at("17:30").do(distance_fixer)
    run_schedule()


def run_job()
    p = Process(target=run_crawler_schedule)
    c = Process(target=run_fix)
    p.start()
    c.start()
    p.join()
    c.join()

if __name__ == "__main__":
    run_job()