H
H
hpmalo2018-04-07 17:07:09
Python
hpmalo, 2018-04-07 17:07:09

How to loop through functions every 30 minutes, hour, etc?

There are many different functions that parse data, each of them should be triggered every 30 minutes, an hour, and so on. How can it be implemented?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2018-04-07
@hpmalo

Times option:

import sched, time

s = sched.scheduler(time.time, time.sleep)

def f():
    s.enter(5, 1, f)  # Перезапуск через 5 секунд
    print(time.time())

f()
s.run()

Two option:
import threading

def f():
  threading.Timer(5.0, f).start()  # Перезапуск через 5 секунд
  print("Hello!")

f()

A very stupid one:
import time

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

while True:
    time.sleep(5)
    f()

J
jistulamle, 2018-04-07
@jistulamle

Linux has a job scheduler called cron.

P
pfg21, 2018-04-07
@pfg21

better sistemd.timer - more options and options.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question