Exception Handling

Schedule doesn’t catch exceptions that happen during job execution. Therefore any exceptions thrown during job execution will bubble up and interrupt schedule’s run_xyz function.

If you want to guard against exceptions you can wrap your job function in a decorator like this:

import functools

def catch_exceptions(cancel_on_failure=False):
    def catch_exceptions_decorator(job_func):
        def wrapper(*args, **kwargs):
                return job_func(*args, **kwargs)
                import traceback
                if cancel_on_failure:
                    return schedule.CancelJob
        return wrapper
    return catch_exceptions_decorator

def bad_task():
    return 1 / 0


Another option would be to subclass Schedule like @mplewis did in this example.