在不重新加载的烧瓶中使用flask_apscheduler无法正常工作

时间:2018-11-27 12:20:03

标签: python flask reload apscheduler

我正在尝试在我的Flask应用程序中安排任务,它无法按预期工作,当我将process = 2设置为process = 1时没有错误。为什么?

这样的代码:

#--coding:utf-8 --*--
import sys
import os 
reload(sys)  
sys.setdefaultencoding('utf-8')

from flask import Flask
from flask_apscheduler import APScheduler

from apscheduler.jobstores.sqlalchemy import SQLAlchemyJobStore

#the configuration of app.
class Config():
    SCHEDULER_JOBSTORES = {
            'default': SQLAlchemyJobStore(url='sqlite:///flask_aps_test.db')
        }

    SCHEDULER_API_ENABLED = True

    ENCODING = 'utf8'

    DEBUG = True

    THREADED = True

#the initialization of app.
app = Flask(__name__)

app.config.from_object(Config())

#the initialization of scheduler.
scheduler = APScheduler()

scheduler.init_app(app)

scheduler.start()

#the function of hello is a schedule task.
def hello():

    print "hello, world."

@app.route('/index')
def test_aps():
    print "before,",scheduler.get_jobs()

    if scheduler.get_job(id='1001'):

        scheduler.remove_job(id = '1001') #if the job_id is exists then remove it.

    else:
        scheduler.add_job( id = '1001',
                        func = hello,
                        trigger = 'interval',
                        seconds = 5,
                        replace_existing = True)

    print "after,",scheduler.get_jobs()

    return "ok."


if __name__ == '__main__':
    #when i set processes = 2 it not working,except processes = 1.
    app.run(processes = 2)

结果是:

  
      
  • http://127.0.0.1:5000/上运行(按CTRL + C退出)*   用stat重新启动*调试器处于活动状态! *调试器PIN:   668-587-681之前,[]之后,[]   127.0.0.1--[27 / Nov / 2018 19:50:26]“ GET / index HTTP / 1.1” 200-*检测到更改   '/Users/akeemqin/Documents/workstation/test/flask_test_1.py',   重新加载*使用stat重新启动*调试器处于活动状态!没有处理程序   可以找到记录器“ apscheduler.executors.default” *调试器   PIN:668-587-681您好,世界。你好,世界。你好,世界。你好,   世界。你好,世界。你好,世界。之前,[]   之后,[]
  •   

0 个答案:

没有答案