Search code examples
pythonapscheduler

Apscheduler script file stops silently - no error


I have a scheduler_project.py script file.

code:

from apscheduler.schedulers.background import BackgroundScheduler
scheduler = BackgroundScheduler()

def func_1():
   # updating file-1

def func_2():
   # updating file-2

scheduler.add_job(func_1, 'cron', hour='10-23' , minute='0-58', second=20)
scheduler.add_job(func_2, 'cron', hour='1')

scheduler.start()

When I run, (on Windows machine)

E:\> python scheduler_project.py 
E:\>                            # there is no error

In Log: (I have added logging in above code at debug level)

It says, job is added and starts in (some x seconds), but it is not starting.

In task manager, the command prompt process display for a second and disappear.

And my files are also not getting updated, which is obvious.

What's happening? What is the right way to execute this scheduler script?


Solution

  • Scheduler was created to run with other code - so after starting scheduler you can run other code.

    If you don't have any other job then you have to use some loop to run it all time.

    In documentation you can see link to examples on GitHub and one of example uses

    while True:
        time.sleep(2)