python apscheduler没有关闭 [英] python apscheduler not shutting down

查看:179
本文介绍了python apscheduler没有关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过删除 job 并完全关闭它来阻止 apscheduler 继续运行!

它们都不起作用,我的函数 expire_data 仍然被触发

def process_bin(value):打印存储:",pastebin.value打印将过期",pastebin_duration.value,秒!"如果 pastebin_duration>=0:调度程序 = BlockingScheduler()job=scheduler.add_job(expire_data, 'interval', seconds=5)调度程序.start()作业.remove()scheduler.shutdown()def expire_data():打印删除数据!"

我怎样才能阻止它?

解决方案

问题:我试图阻止 apscheduler 运行

您正在使用 BlockingScheduler,因此您不能.

<块引用>

APScheduler BlockingScheduler

BlockingScheduler 是最简单的调度器.
它在前台运行,因此当您调用 start() 时,调用永远不会返回.

<小时><块引用>

阅读选择合适的调度器

  • BlockingScheduler:当调度程序是你的进程中唯一运行的东西时使用
  • BackgroundScheduler:当您不使用以下任何框架,并希望调度程序在您的应用程序的后台运行时使用
  • AsyncIOScheduler:在您的应用程序使用 asyncio 模块时使用
  • GeventScheduler:在您的应用程序使用 gevent 时使用
  • TornadoScheduler:在您构建 Tornado 应用程序时使用
  • TwistedScheduler:在构建 Twisted 应用程序时使用
  • QtScheduler:在您构建 Qt 应用程序时使用

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?

解决方案

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

这篇关于python apscheduler没有关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆