Commit 643753d6 authored by Romain Baptiste Dominique Albert's avatar Romain Baptiste Dominique Albert
Browse files

Change in the way the first temperature request is made. Make it more robust...

Change in the way the first temperature request is made. Make it more robust as we does not rely anymore on some sleep but on a timeout for the request.
parent dedc24ac
......@@ -60,21 +60,28 @@ class SensorReader(metaclass=Singleton):
if self.thread is None or not self.thread.is_alive():
self.thread = Thread(target=self.reader.run, daemon=True)
self.thread.start()
time.sleep(0.1)
# We warn the thread that a request was made to keep it alive
self.request_queue.put(1)
# If it is the first reading and if nothing was send back by the thread,
# we generate an error.
try:
data_temp = self.data_queue.get(block=True, timeout=1.)
except Empty:
if self.data is None:
raise Exception('It was not possible to get the temperature')
else:
return
# We try to get last reading from the thread, and update the data structure if there is
# new data.
# If it is the first reading and nothing was send back by the thread, we generate an error.
try:
data_temp = self.data_queue.get(block=False)
except Empty:
if self.data is None:
raise Exception('It was not possible to get the temperature')
else:
else:
# We warn the thread that a request was made to keep it alive
self.request_queue.put(1)
# We try to get last reading from the thread, and update the data structure if there is
# new data.
try:
data_temp = self.data_queue.get(block=False)
except Empty:
return
self.data = data_temp
def sensor_list(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment