python - Django 中的 Apscheduler Job 执行两次
问题描述
计划的作业执行两次,以纳秒为单位。我在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
推荐阅读
- arrays - Maximize sum of array after applying the given operations on the array
- java - Java 8 和 Java 11 中 LocalDateTime 到毫秒的差异
- oracle - Oracle 中触发器或计划作业中的更新语句?
- .net-core - Serilog 与 Application Insights 的 Azure 功能集成,日志在搜索中可见但未出现在故障事件时间线中
- laravel - 如何更改 Laravel Spark PDF 收据中的默认文本?
- qt - 如何在 Qt 中更改复选框样式
- amazon-web-services - 如果我的服务器请求向 URL 发出 post 请求,该服务器会收到什么信息?
- php - SQLSTATE [HY000]:一般错误:1364 字段“图像”没有默认值
- ios - 如何快速修复成功和失败案例的 Alamofire 5 错误?
- json - 处理 foreach 中的排除元素