相关文章推荐
英勇无比的领带  ·  python ...·  1 周前    · 
开朗的枕头  ·  精通 Oracle+Python,第 3 ...·  12 小时前    · 
逼格高的板栗  ·  Visual Studio ...·  2 年前    · 
聪明的鞭炮  ·  MySQL ...·  2 年前    · 
发财的煎饼果子  ·  sharepoint - Deploy a ...·  2 年前    · 
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!

Maybe you're using an older version of APScheduler, but the import doesn't work for me of Scheduler . That said, there are multiple flavors of the scheduler. You likely want a BackgroundScheduler , unless your code is able to sit and block after you .start() . In that case, I'd probably start the scheduler in its own thread or process. JoshAdel Feb 8, 2017 at 17:48 @JoshAdel I just tried it with the newer version 3.x changed from apscheduler.scheduler import Scheduler to from apscheduler.schedulers.background import BackgroundScheduler and sched = Scheduler() to sched = BackgroundScheduler() I get the same result. James Feb 8, 2017 at 18:20 If you are using a BackgroundScheduler then you need to have the code do something to keep the main thread alive otherwise it will exit immediately. See github.com/agronholm/apscheduler/blob/master/examples/… and other examples in that directory of the repo. JoshAdel Feb 8, 2017 at 18:40

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 .