python apscheduler not shutting down

2019-09-18 07:27发布

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条回答
Animai°情兽
2楼-- · 2019-09-18 07:42

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
查看更多
登录 后发表回答