Python task scheduling

I want to run a program that runs a function every 4 hours. What is the least capable way to do this?

+3
source share
3 answers

The easiest way I can think of (in python, since the post is tagged with python):

import time

while True:
  do_task()
  time.sleep(4 * 60 * 60) # 4 hours * 60 minutes * 60 seconds
+6
source

You can use schedmodule

Here are the docs

https://docs.python.org/3.4/library/sched.html

+4
source

Use the built-in timer:

from threading import Timer

def function_to_be_scheduled():
   """Your CODE HERE"""

interval = 4 * 60 * 60   #interval (4hours)

Timer(interval, function_to_be_scheduled).start() 
+3
source

Source: https://habr.com/ru/post/1745863/


All Articles