I'm trying to use a decorator for a function, while trying to pass a global variable to the decorator. However, I get an error message at the line with the decorator (@) stating that scheduler
is not defined...
def wrap_task(scheduler_in):
def inner(task):
try:
task()
except:
logger_sub.exception("Error!!!!")
scheduler_in.shutdown(wait=False)
return inner
@wrap_task(scheduler_in = scheduler)
def print_job():
print("pipeline")
raise FileExistsError
if __name__ == "__main__":
scheduler = BlockingScheduler() # from APScheduler
scheduler.add_job(print_job,'date',id="print_job")
scheduler.add_listener(my_listener,EVENT_JOB_EXECUTED | EVENT_JOB_ERROR)
(...)
P.S.: The problem shouldn't be to use scheduler
before it's defined, since I also create a listener for this scheduler and the listener itself uses the same shutdown command without any error.