Stopping the scheduler after certain number of iterations

133 views
Skip to first unread message

Dusan Boskovic

unread,
Aug 10, 2017, 11:28:09 AM8/10/17
to APScheduler
Hi,
I am using APScheduler to run one of my functions, and I wanted to know if there was a way to only run the scheduler a specific amount of times, say 3.

Currently, this is my following code structure

from apscheduler.schedulers.blocking import BlockingScheduler
from dp_event_handler_module import case2_newconfig
import os



def main_func():
scheduler = BlockingScheduler()
scheduler.add_executor('threadpool')
scheduler.add_job(case2_newconfig.process_new_tracking_data, 'interval', seconds=15, id='new_tracking_data')
print('Press Ctrl+{0} to exit'.format('Break' if os.name == 'nt' else 'C'))
scheduler.print_jobs()

try:
scheduler.start()
except (KeyboardInterrupt, SystemExit):
pass

I want the scheduler to stop after three iterations of the process_new_tracking_data function. Is there a way of doing this?

Thanks

Alex Grönholm

unread,
Aug 10, 2017, 1:49:40 PM8/10/17
to apsch...@googlegroups.com

Have you tried stopping the scheduler from the job's target function on the third iteration? Just make sure you use scheduler.shutdown(False) to avoid a deadlock.

If that's no good, you can use an event listener to track job executions.

--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages