python apscheduler not shutting down

风流意气都作罢 提交于 2019-12-12 05:37:58

问题


I'm trying to stop the apscheduler from running on by removing the job and shutting it down completely!

None of them is working, my function expire_data still gets triggered

def process_bin(value):
    print "Stored:",pastebin.value
    print "Will expire in",pastebin_duration.value,"seconds!"

    if pastebin_duration>=0:
        scheduler = BlockingScheduler()
        job=scheduler.add_job(expire_data, 'interval', seconds=5)
        scheduler.start()
        job.remove()
        scheduler.shutdown()

def expire_data():
    print "Delete data!"

How can I stop it?


回答1:


Question: I'm trying to stop the apscheduler from running

You are using a BlockingScheduler, therefore you can't.

APScheduler BlockingScheduler

BlockingScheduler is the simplest possible scheduler.
It runs in the foreground, so when you call start(), the call never returns.


Read about Choosing the right scheduler

  • BlockingScheduler: use when the scheduler is the only thing running in your process
  • BackgroundScheduler: use when you’re not using any of the frameworks below, and want the scheduler to run in the background inside your application
  • AsyncIOScheduler: use if your application uses the asyncio module
  • GeventScheduler: use if your application uses gevent
  • TornadoScheduler: use if you’re building a Tornado application
  • TwistedScheduler: use if you’re building a Twisted application
  • QtScheduler: use if you’re building a Qt application


来源:https://stackoverflow.com/questions/44313801/python-apscheduler-not-shutting-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!