Created
July 4, 2015 13:17
-
-
Save Yogatopia/71068e17d43a3a7dd96a to your computer and use it in GitHub Desktop.
Python Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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