1 | initial version |
There are two ways to prevent apscheduler from causing the application to exit:
daemon
parameter of the scheduler to False
: By default, the daemon
parameter of apscheduler is set to True
, which means that the scheduler will run in the background as a daemon thread. If you set this parameter to False
, the scheduler will run as a normal thread and will not cause the application to exit.from apscheduler.schedulers.blocking import BlockingScheduler
def my_job():
print('Hello')
if __name__ == '__main__':
scheduler = BlockingScheduler(daemon=False)
scheduler.add_job(my_job, 'interval', seconds=10)
scheduler.start()
from apscheduler.schedulers.blocking import BlockingScheduler
def my_job():
print('Hello')
if __name__ == '__main__':
scheduler = BlockingScheduler()
scheduler.add_job(my_job, 'interval', seconds=10)
scheduler.start()