Created
October 19, 2011 01:12
-
-
Save stefanv/1297234 to your computer and use it in GitHub Desktop.
Observer thread
This file contains 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 | |
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