Skip to content

Instantly share code, notes, and snippets.

@Yogatopia
Created July 4, 2015 13:17
Show Gist options
  • Save Yogatopia/71068e17d43a3a7dd96a to your computer and use it in GitHub Desktop.
Save Yogatopia/71068e17d43a3a7dd96a to your computer and use it in GitHub Desktop.
Python Snippets
import threading
def do_every (interval, worker_func, iterations = 0):
if iterations != 1:
threading.Timer (
interval,
do_every, [interval, worker_func, 0 if iterations == 0 else iterations-1]
).start ()
worker_func ()
def print_hw ():
print ("hello world")
def print_so ():
print ("stackoverflow")
# call print_so every second, 5 times total
do_every (1, print_so, 5)
# call print_hw two times per second, forever
#do_every (0.5, print_hw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment