Scheduling a Minute-Interval Time Printing Task

  • Share this:

Code introduction


This function uses the Schedule library to create a task that runs every minute. This task calls the print_time function to print the current time.


Technology Stack : Schedule library, time library (time)

Code Type : Timed task

Code Difficulty : Intermediate


                
                    
import schedule
import time

def run_every_minute():
    schedule.every().minute.do(print_time)
    while True:
        schedule.run_pending()
        time.sleep(1)

def print_time():
    print("Current time:", time.strftime("%Y-%m-%d %H:%M:%S"))