Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
def start_timers(self):
self.sched.start()
self.sched.add_cron_job(self.queue_job, minute='0-59')
if __name__ == "__main__":
from time_keeper import TimeKeeper
TimeKeeper().start_timers()
The problem is, once the script is executed it runs for a split second then stops, there are no traceback errors.
Is the function incorrectly called or am I missing some parts of code? The Communities help would be much appreciated!
–
–
–
The formal answer to your issue is that when using APScheduler v2, the default behavior of the scheduler is to run in threaded mode, which will return immediately after you apply the
.start()
:
https://github.com/agronholm/apscheduler/blob/2.1/apscheduler/scheduler.py#L90-L91
Since it returns immediately and nothing keeps the main thread of your program alive, your program exits immediately. You need to keep your programming running long enough so that the scheduler can fire an event, or you need to run using a blocking version of the scheduler.
For this older version of APscheduler, you need to run in standalone mode if you want the scheduler to block:
https://github.com/agronholm/apscheduler/blob/2.1/examples/interval.py
or you if you want to continue running in threaded mode:
https://github.com/agronholm/apscheduler/blob/2.1/examples/threaded.py
Newer versions of APScheduler have separate
BlockingScheduler and
BackgroundScheduler` classes and you should consult the appropriate examples for the updated API.
Thanks for contributing an answer to Stack Overflow!
-
Please be sure to
answer the question
. Provide details and share your research!
But
avoid
…
-
Asking for help, clarification, or responding to other answers.
-
Making statements based on opinion; back them up with references or personal experience.
To learn more, see our
tips on writing great answers
.