November 2018
Intermediate to advanced
446 pages
12h 11m
English
One additional functionality offered by APScheduler is the ability to distribute scheduled jobs to be executed across multiple CPU cores (or processes). In this example, you will learn how to do that with a background scheduler. Navigate to the Chapter19/example3.py file and inspect the included code, as follows:
# Chapter19/example3.pyfrom datetime import datetimeimport timeimport osfrom apscheduler.schedulers.background import BackgroundSchedulerdef task(): print(f'From process {os.getpid()}: The time is {datetime.now()}') print(f'Starting job inside {os.getpid()}') time.sleep(4) print(f'Ending job inside {os.getpid()}')if __name__ == '__main__': scheduler = BackgroundScheduler() scheduler.add_executor('processpool') scheduler.add_job(task, ...Read now
Unlock full access