Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get return value from apscheduler jobs

Tags:

python-3.x

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 this ? Thanks very much.

like image 864
Jason Avatar asked Sep 01 '25 03:09

Jason


1 Answers

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

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


sched = BlockingScheduler()
times = 0

# Execute fn() each second.
sched.add_job(fn, trigger=CronTrigger(second='*/1'))
sched.start()
like image 57
Sergei Bondarenko Avatar answered Sep 02 '25 22:09

Sergei Bondarenko