Skip to content

Instantly share code, notes, and snippets.

@DomNomNom
Created November 17, 2014 10:31
Show Gist options
  • Save DomNomNom/ab89b51d875a3982a4af to your computer and use it in GitHub Desktop.
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
'''
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:
print
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