Python Program To Schedule A Job To Run Every Hour
Chapter:
Python
Last Updated:
10-08-2023 15:37:33 UTC
Program:
/* ............... START ............... */
import schedule
import time
def hourly_job():
print("This job runs every hour.")
# Schedule the job to run every hour
schedule.every().hour.do(hourly_job)
# Run the scheduler
while True:
schedule.run_pending()
time.sleep(1)
/* ............... END ............... */
Notes:
-
This Python program uses the schedule library to schedule and run a specific task at regular intervals, in this case, every hour.
- In this example, the hourly_job function will be executed every hour. The schedule.every().hour.do(hourly_job) line sets up the scheduling, and the schedule.run_pending() function checks if there are any pending jobs to run every second.
- Remember to customize the hourly_job function to contain the actual code you want to execute every hour. You can modify the script as needed to fit your specific requirements.