1

Is it possible to execute the code asynchronously in predefined intervals in Python like it's done in JS using the setTimer?

For example, the function example() will be called every 60 seconds in Python. How can I do that?

3
  • I think you should be able to do it using threads. Commented Oct 25, 2019 at 19:03
  • Run a thread that performs a loop that calls example() and then os.sleep(60) Commented Oct 25, 2019 at 19:04
  • Maybe this will help stackoverflow.com/q/2697039/2776525 Awesome username btw Commented Oct 25, 2019 at 19:05

1 Answer 1

1
import threading

def printit():
  threading.Timer(5.0, printit).start()
  print "Hello, World!"

printit()

the answer from: Run certain code every n seconds

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.