import atexit
import multiprocessing

from TSL2561 import TSL2561
from MCP9808 import MCP9808
import time


class SensorsHelper(object):
    def __init__(self, pipe):
        self._pipe = pipe

    def sensors_thread(self):
        tsl = TSL2561(debug=0)
        mcp = MCP9808(debug=0)
        #tsl.set_gain(16)

        while True:
            #full = tsl.read_full()
            #ir = tsl.read_IR()
            lux = tsl.read_lux()
            #print("%d,%d = %d lux" % (full, ir, lux))
            temp = mcp.read_temp()
            #print("%0.2f degC" % temp)

            self._pipe.send({'lux': lux, 'temp': temp})

            time.sleep(1)


class Sensors(object):
    ''' Class for reading and reporting sensor values '''
    def __init__(self):
        self._child_pipe, self._pipe = multiprocessing.Pipe(duplex=True)
        self._helper = SensorsHelper(self._child_pipe)
        self._readings = None

    def begin(self):
        self._p = multiprocessing.Process(target=self._helper.sensors_thread)
        self._p.start()
        atexit.register(self.end)

    def end(self):
        self._pipe.send('end')
        self._p.join()

    def get_latest(self):
        while self._pipe.poll():
            self._readings = self._pipe.recv()
        return self._readings

@@ -326,16 +326,92 @@
 e True:%0A
+            temp = mcp.read_temp()%0A            #print(%22%250.2f degC%22 %25 temp)%0A%0A
         
@@ -558,16 +558,17 @@
 , lux))%0A
+%0A
         
@@ -575,72 +575,129 @@
     
-temp = mcp.read_temp()%0A            #print(%22%250.2f degC%22 %25 temp)%0A%0A
+self._pipe.send(%7B'temp': temp, 'lux': lux%7D)%0A%0A            # check for end signal%0A            while self._pipe.poll():%0A    
     
@@ -695,32 +695,38 @@
 %0A               
+ val =
  self._pipe.send
@@ -725,40 +725,74 @@
 ipe.
-send(%7B'lux': lux, 'temp': temp%7D)
+recv()%0A                if val == 'end':%0A                    return
 %0A%0A  
@@ -1237,16 +1237,144 @@
 elf.end)
+%0A        # Get an initial reading (so get_latest() is guaranteed to return something)%0A        self._readings = self._pipe.recv()
 %0A%0A    de

Fix bogus initial sensor reading.