Search code examples
pythontiming

How to schedule jobs to start at the beginning of each hour


I want to schedule a task at the start of every hour , I don't want to have the initial time to when the script ,but i want the task to be started like at the start of every hour of system time in python


Solution

  • I use a library called schedule made by Dan Bader for scheduling my tasks. It is quite easy to use this and you can do like the following as mentioned in the documentation:

    import schedule
    import time
    
    def job():
        print("I'm working...")
    
    schedule.every().hour.do(job)
    
    while True:
        schedule.run_pending()
        time.sleep(1)
    


    Installation:

    pip install schedule
    

    To know more ways to schedule like particular time, hour, etc, check out his documentation.