Skip to content

Instantly share code, notes, and snippets.

@torufurukawa
Created April 10, 2014 01:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torufurukawa/10335350 to your computer and use it in GitHub Desktop.
Save torufurukawa/10335350 to your computer and use it in GitHub Desktop.
threading
from time import sleep
from threading import Event, Thread
def main():
# set
to_run = Event()
to_run.set()
# start thread
worker = Worker(to_run, 1)
worker.start()
print 'worker started'
# wait for 5 sec
sleep(5)
# clear
to_run.clear()
class Worker(Thread):
def __init__(self, to_run, interval):
Thread.__init__(self)
self.to_run = to_run
self.interval = interval
def run(self):
while True:
if not self.to_run.is_set():
break
print 'hello'
sleep(self.interval)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment