Easiest way to Run a Python Script in the Background

The easiest way of running a python script to run in the background is to use cronjob feature (in macOS and Linux). In windows, we can use Windows Task Scheduler.

In Mac or Linux, open the terminal using the following command to check what jobs are running in the background

crontab -l

Now, to edit the list type the following command

crontab -e

You can then give the path of your python script file to run at a specific time by giving the time particulars. Now enter the following and press CTRL+O and CTRL+X to save and exit.

Presently I have two jobs scheduled to run in the background as can be seen from the below screenshot

Learn More

Tags: Python script