Created
November 17, 2014 10:31
-
-
Save DomNomNom/ab89b51d875a3982a4af to your computer and use it in GitHub Desktop.
An example of having a function being called regularly while still processing user input
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
''' | |
An example of having a function being called regularly | |
while still processing user input | |
''' | |
import threading | |
# the regular event | |
timer = None | |
def regularEvent(): | |
print ' ====== regular event ====== ' | |
global timer | |
timer = threading.Timer(5, regularEvent) | |
timer.start() | |
regularEvent() | |
# our input loop | |
try: | |
while True: | |
line = raw_input('what do you want capitalized? (Ctrl+C to exit) \n') | |
print line.upper() | |
except KeyboardInterrupt: # Ctrl+C | |
pass | |
# cleanup | |
# stop the regular event | |
timer.cancel() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment