Skip to content

Instantly share code, notes, and snippets.

@stefanv
Created October 19, 2011 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefanv/1297234 to your computer and use it in GitHub Desktop.
Save stefanv/1297234 to your computer and use it in GitHub Desktop.
Observer thread
import threading
import time
class Worker(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.val = 0
self.val2 = 20
def run(self):
while 1:
time.sleep(1)
self.val += 1
class Observer(threading.Thread):
def __init__(self, worker):
threading.Thread.__init__(self)
self.worker = worker
def run(self):
while 1:
print self.worker.val
time.sleep(1)
w = Worker()
w.start()
o = Observer(w)
o.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment