November 2018
Intermediate to advanced
446 pages
12h 11m
English
In this example, we will look at whether the use of the BackgroundScheduler class would help if we wanted to execute our scheduler in the background, concurrent with other tasks. The code for this example is included in the Chapter19/example2.py file, as follows:
# Chapter19/example2.pyfrom datetime import datetimeimport timefrom apscheduler.schedulers.background import BackgroundSchedulerdef tick(): print(f'Tick! The time is: {datetime.now()}')if __name__ == '__main__': scheduler = BackgroundScheduler() scheduler.add_job(tick, 'interval', seconds=3) scheduler.start() try: while True: time.sleep(2) print('Printing in the main thread.') except KeyboardInterrupt: passscheduler.shutdown()
The code in this example is almost ...
Read now
Unlock full access