【发布时间】:2015-12-01 05:32:31
【问题描述】:
我在 python 的 apscheduler 库中出现了意外行为。
这里我有一个简单的代码来调用基本函数:
import sys
from time import sleep
from datetime import datetime
from apscheduler.scheduler import Scheduler
import logging
logging.basicConfig()
count = 0;
# start the scheduler
# define the function that is to be executed
# it will be executed in a thread by the scheduler
def my_job():
print "hello world"
def main():
sched = None
while True:
sched=Scheduler()
sched.start()
sched.add_cron_job(my_job,second=3)
sched.print_jobs()
sleep(5)
sys.stdout.write('.'); sys.stdout.flush()
##############################################################
if __name__ == "__main__":
main()
这里我有一个打印简单字符串的函数,我想让这个调用这个 my_job 所以我使用调度程序调用了一个 my-func
sched.add_cron_job(my_job,second=3)
程序在每分钟的第三秒调用所需的函数。它将多个 hello world 打印为
hello world
hello world
hello world
多次执行时满足。
我对调度程序的行为感到困惑。调度时间到了怎么能多次调用函数??
【问题讨论】:
标签: python apscheduler