首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

apscheduler 为啥不运行呢

2012-09-06 
apscheduler 为什么不运行呢?今天装了apscheduler,照着官网写了例子(我的环境:python2.7):Python codefrom

apscheduler 为什么不运行呢?
今天装了apscheduler,照着官网写了例子(我的环境:python2.7):

Python code
from apscheduler.scheduler import Schedulerimport datetime# Start the schedulersched = Scheduler()sched.start()# Define the function that is to be executeddef my_job(text):    print text# The job will be executed on November 6th, 2009exec_date = datetime.datetime(2011, 9, 8,12,30,0)# Store the job in a variable in case we want to cancel itjob = sched.add_date_job(my_job, exec_date, ['text'])

为什么不运行呢?按照这个定义,它会在2011/9/8 12:30:00 触发的。我运行之后,没有发现挂起的线程,直接就结束了。


[解决办法]
前段时间写一个调度任务用到这个框架时也碰到了这个问题
因为主线程执行时间比较短,默认开启的守护线程在主线程执行结束后自动关闭了
你可以在start()方法调用前设置daemonic为False可以解决线程不挂起的问题

热点排行