python中的BackgroundScheduler正在运行两个实例,而不是1个

2024-04-20 13:18:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python中的后台调度程序运行一个作业,该作业执行分析,然后更新数据库。以下是相同的代码: 所以预期的行为是它将运行一个线程并等待15秒,然后运行第二个实例。但这是同时运行两个实例,然后休息59秒。下面是我正在运行的带有时间戳的作业的输出

scheduler.add_job(func=print_date_time, trigger="interval",seconds=59)

scheduler.start()

print(scheduler.get_jobs())```




```job started at  02:54:11
 in the beginning tweetid :  blank new tid is :  1090278987920740353
tid not in the database
job finished 
job started at  02:54:13
 in the beginning tweetid :  blank new tid is :  1090278987920740353
tid not in the database
job finished 
job started  02:55:10
 in the beginning tweetid :  blank new tid is :  1090278987920740353
tid not in the database
job finished 
job started  02:55:12
 in the beginning tweetid :  blank new tid is :  1090278987920740353
tid not in the database
job finished *************************************************************************************************************************************

我正在尝试实现python的这个flask应用程序。 这会导致在数据库中插入密钥两次,并且出现重复输入错误


Tags: theinnewis作业notjobdatabase
1条回答
网友
1楼 · 发布于 2024-04-20 13:18:32

你可以试试simple-scheduler

from simple_scheduler.recurring import recurring_scheduler
recurring_scheduler.add_job(target=print_date_time,
                            period_in_seconds=59,
                            job_name="print_date_time")
recurring_scheduler.job_summary()
recurring_scheduler.run()
recurring_scheduler.job_summary()

相关问题 更多 >