I have a hardware sensor. I need to continuously read the sensor and perform some math on the prior 3 seconds worth of readings. (The faster I read, the more samples I have, the better my result, so I want to continuously call my function.) I need to provide the user (via a web call) the current result at the time of the request. Results may change significantly on a sub-second basis. The user may request an update as fast as possible or very infrequently. 

I currently have the following code, which works.

```
from threading import Thread
from MySensorReadAndMath import MySensorReadAndMath

class ManageSensor(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.result={}
        self.mySensorReadAndMath = MySensorReadAndMath()
    def updateResult(self):
        result = {}
        result['value1'] = self.mySensorReadAndMath.value1
        result['value2'] = self.mySensorReadAndMath.value2
        return result
    def getResult(self):
        return self.result
    def run(self):
        while True:
            self.mySensorReadAndMath.update()
            self.result = self.updateResult()

```

In a separate piece of code, I create the class, use Flask to create a web call to *ManageSensor.getResult()* to return the result, and start the thread.

Is this thread-safe? (Could I get the current *value1* and prior *value2*, or a corrupt *self.result*?) If it is not thread-safe, how would I make it thread-safe without ever blocking?

Specific things I have considered:

1. Do I get any benefit by first copying the values into a local *result* in *updateResults()* (compared to directly putting everything directly into *self.result* in *updateResult()*
2. If I put locks around updating *self.result*, then my *run()* loop or my *getResult()* may block which I don't want.
3. If I push the result onto a queue within *run()* and pop it within *getResult()*, I will have issues with the queue size since I will never call *getResult()* as fast as *self.mySensorReadAndMath.update()* runs.
4. Am I over-thinking this? :)