我已使用this安排了我的任务:
if __name__ == '__main__':
channel_crawler(priority=1)
schedule.every(PRIORITY[1]["interval"]).minutes.do(channel_crawler, priority=1)
schedule.every().day.at("17:30").do(distance_fixer)
while True:
schedule.run_pending()
time.sleep(1)
channel_crawler
需要5 minutes
才能投放,distance_fixer
需要约5 hours
。当我在运行distance_fixer
时运行代码时,每个channel_crawler
的计划都不会运行10 minutes
。如何并行运行我的功能?
答案 0 :(得分:2)
您可以对作业使用多处理,因此每个进程都运行每个函数
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()