Skip to content Skip to sidebar Skip to footer

How To Get Return Value From Apscheduler Jobs

I'm using apscheduler to arrange some jobs. Some of the jobs have return values after the job be executed. How can I get the return values from these jobs ? Does anyone has idea on

Solution 1:

You can add a listener to your scheduler. See the following links:

Here you can see how to add a listener and here the so called JobExecutionEvent is described. This event provides the return value that you are looking for.

Solution 2:

The feature is still under development, but you can use global variables for now. Here's an example:

from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger

deffn():
    '''Increase `times` by one and print it.'''global times
    times += 1print(times)


sched = BlockingScheduler()
times = 0# Execute fn() each second.
sched.add_job(fn, trigger=CronTrigger(second='*/1'))
sched.start()

Post a Comment for "How To Get Return Value From Apscheduler Jobs"