LRDPRDX
LRDPRDX

Reputation: 682

What argument max_instances means in APSchedulers

I have the following code:

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()

i.e. I want to call the function TrigFreq 10 times with interval of 3 sec. But it never stops. What am I doing wrong?

Upvotes: 2

Views: 6599

Answers (2)

rhoitjadhav
rhoitjadhav

Reputation: 903

You just need to add one argument in order to stop the job on specified date and time. So pass the argument i.e end_date like this.

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()

Source: From Apscheduler 3.6 documentation

Upvotes: 0

Dutch Masters
Dutch Masters

Reputation: 1469

Yes your trigger, using interval will run forever. The max_instances only tells you how many concurrent jobs you can have.

APScheduler has three types of triggers: date interval cron

interval and cron repeat forever, date is a one-shot on a given date. If you want a trigger that triggers 10 times and then stops, then you would write a custom trigger based off either SimpleTrigger or IntervalTrigger, which keeps track of a counter so that it will stop triggering after the count runs out.

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

Upvotes: 2

Related Questions