I am trying to contribute to a project on Github for collecting financial data.
The code..
# time_keeper.py
from apscheduler.scheduler import Scheduler
class TimeKeeper:
def __init__(self):
self.sched = Scheduler()
def queue_job(self):
print("message send to queue")
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!
Scheduler
. That said, there are multiple flavors of the scheduler. You likely want aBackgroundScheduler
, 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. – Swirlfrom apscheduler.scheduler import Scheduler
tofrom apscheduler.schedulers.background import BackgroundScheduler
andsched = Scheduler()
tosched = BackgroundScheduler()
I get the same result. – ConsultationBackgroundScheduler
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. – Swirl