zoukankan      html  css  js  c++  java
  • falsk 定时任务

    参照连接: https://blog.csdn.net/qq_22034353/article/details/89362959

      pip install flask_apscheduler

    1  在core.py 导入相关模块 

    from flask_apscheduler import APScheduler
    scheduler = APScheduler()
    

    2在factory.py  配置定时任务信息 

    from core import scheduler 
    from web_f import app # web_f 是我的falsk主文件
    app.config.update(
            {"SCHEDULER_API_ENABLED": True,
             "JOBS": [{"id": "my_job", # 任务ID
                        "func": "task:my_job",#任务位置 # 当前文件
                        "trigger": "interval", #触发器
                        "seconds": 60 # 时间间隔
                        }
                    ]}
            )
    scheduler.init_app(app)
    scheduler.start()
    

    3 在当前文件夹下创建task.py # 任务

    import datetime,os
    def my_job():
    	print(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
    

      

    4 运行falsk 开始执行定时任务

  • 相关阅读:
    Python shutil模块
    Flask 上传文件
    Flask DBUtils
    flash-session
    Flash 上下文管理
    python 栈
    python 偏函数
    threding.local
    next() 与 nextLine() 区别
    Thread.sleep(1000*3); // 休眠3秒
  • 原文地址:https://www.cnblogs.com/zhangshijiezsj/p/15123842.html
Copyright © 2011-2022 走看看