How do I execute a command once every hour in python?

Asked

Viewed 2,194 times

-1

I want to run a code/line code once every hour while running the script in python, as I run every hour?

  • What is the operating system? You would probably have to schedule the execution of a script, see this question in Soen: https://stackoverflow.com/q/2725754/8133067

2 answers

2


I recommend you take a look at the library Schedule

import schedule
import time

def f():
    print("Hello World")

schedule.every().hour.do(f)

while True:
    schedule.run_pending()
    time.sleep(1)

1

A north for you to use in your code to run every hour.

import time
while True:
    print("passou 1 hora executa esse comando")
    time.sleep(3600) #A cada hora ele executa o print

Browser other questions tagged

You are not signed in. Login or sign up in order to post.