Chapter 14
Scheduling Tasks
IN THIS CHAPTER
Automating with the schedule and APScheduler modules
Running scripts as subprocesses and imports
Python is well-suited to scheduling tasks to run at specific dates and times, as well as at regular intervals. You can schedule system tasks like backups and logging. You can also schedule internet-related tasks like web scraping, email, and social media posting.
In this chapter, you learn about two libraries that are particularly well-suited to scheduling: schedule and APScheduler. First, I show you the features of each. Then I provide specific examples of how to use them to schedule Python automation tasks.
Using the Schedule Module
A popular module used for scheduling is aptly named schedule. The schedule module isn’t part of the Python standard library. So, if you intend to use it in a script, make sure to create and activate your virtual environment and enter this command at the command prompt in the Terminal:
pip install schedule
You can use the schedule library to run tasks at specific times or at regular intervals. A simple way to get started is to write some simple scripts that just print some feedback in the Terminal, on schedule, so you know that your code works. Here’s a simple script that just displays some feedback in the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access