August 2018
Intermediate to advanced
366 pages
10h 14m
English
BackgroundScheduler subclasses threading.Thread so that it runs in the background while our application is doing something else. Registered tasks will fire and perform in a secondary thread without getting in the way of the primary code:
class BackgroundScheduler(threading.Thread):
def __init__(self):
self._scheduler = sched.scheduler()
self._running = True
super().__init__(daemon=True)
self.start()
Whenever BackgroundScheduler is created, the thread for it is started too, so it becomes immediately available. The thread will run in daemon mode, which means that it won't block the program from exiting if it's still running at the time the program ends.
Usually Python waits for all threads when exiting the application, so setting ...