Django中的ApScheduler作业执行两次 [英] Apscheduler Job in Django executes twice

查看:81
本文介绍了Django中的ApScheduler作业执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

计划的作业执行两次,以纳秒为单位。我在task.py

中有以下任务
def print_hello():
   print("time-->",datetime.datetime.now())
   print("hello")

def print_world():
   print("time-->",datetime.datetime.now())
   print("hello")

scheduler = BackgroundScheduler()
scheduler1 = BackgroundScheduler()

从app文件夹添加app.py包含以下代码行..

from django.apps import AppConfig
from datetime import date
class ExploitDataConfig(AppConfig):
     name = 'exploit_data' 

     def ready(self):
    
         from exploit_data import task   

         task.scheduler.add_job(task.print_hello, 'interval', minutes=5)
         task.scheduler1.add_job(task.print_world, 'interval', minutes=5
         task.scheduler.start()
         task.scheduler1.start()

我希望每隔5分钟仅执行一次任何帮助都是值得感激的..

推荐答案

也许这会有帮助:

python manage.py runserver --noreload

这篇关于Django中的ApScheduler作业执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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