max_instances在APSchedulers中的含义是什么

2024-09-30 02:15:30 发布

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

我有以下代码:

import usbtmc
#import matplotlib.pyplot as plot
from apscheduler.schedulers.background import BlockingScheduler        

instr = usbtmc.Instrument(0x0699, 0x03a6)

print instr.ask("*IDN?")

sched = BlockingScheduler()

def TrigFreq():
  print instr.ask("TRIG:MAI:FREQ?")

sched.add_job( TrigFreq, 'interval', seconds=3, max_instances=10 )
sched.start()

也就是说,我想以3秒的间隔调用函数TrigFreq10次。但它从未停止。我做错什么了?在


Tags: 代码fromimportplotmatplotlibasaskprint
2条回答

您只需添加一个参数,就可以在指定的日期和时间停止作业。所以传递参数,即end_date,如下所示。在

import usbtmc
#import matplotlib.pyplot as plot
from apscheduler.schedulers.background import BlockingScheduler        

instr = usbtmc.Instrument(0x0699, 0x03a6)

print instr.ask("*IDN?")

sched = BlockingScheduler()

def TrigFreq():
  print instr.ask("TRIG:MAI:FREQ?")

sched.add_job( TrigFreq, 'interval', seconds=3, max_instances=10, end_date='2014-06-15 11:00:00')

sched.start()

来源:From Apscheduler 3.6 documentation

是的,使用interval的触发器将永远运行。max_实例只告诉您可以有多少并发作业。在

APScheduler有三种类型的触发器: date interval cron

interval和cron永远重复,date是给定日期上的一个快照。 如果您希望触发器触发10次然后停止,那么您可以编写一个基于SimpleTrigger或{}的自定义触发器,它跟踪计数器,以便在计数用完后停止触发。在

https://apscheduler.readthedocs.io/en/latest/extending.html

相关问题 更多 >

    热门问题