From 807478953ab6a5402ab9d7c353ad683cd5cc6bc9 Mon Sep 17 00:00:00 2001 From: Takuji Kawata Date: Sun, 20 Aug 2017 21:56:30 +0900 Subject: [PATCH] Fixed fake_sensor.py Added value and register_callback to FakeSensor, they are needed for topic_sensor publishers in the book. --- code/stuff/fake_sensor.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/code/stuff/fake_sensor.py b/code/stuff/fake_sensor.py index 81338c0..f993b9c 100755 --- a/code/stuff/fake_sensor.py +++ b/code/stuff/fake_sensor.py @@ -50,13 +50,23 @@ def run(self): class FakeSensor: def __init__(self): thread = threading.Thread(target=self.run) - thread.daemon = True + thread.daemon = False thread.start() + self.cv = threading.Condition() + with self.cv: + self.cv.wait() def run(self): self.sensor = ActualFakeSensor() + with self.cv: + self.cv.notify() self.sensor.run() + def value(self): + return self.sensor.value() + + def register_callback(self, callback): + self.sensor.register_callback(callback) if __name__ == '__main__': sensor = FakeSensor()