e99146343976c11588982f837c2a75b8ec6291a4
[saartuer.git] / concept_spaceapi.py
1
2
3 class SpaceApi:
4         __init__ (self):
5                 self.state_to_set = None # public write, TODO: getters, setters?
6                 self.state_last_set = None # public read
7                 self._running = True
8                 self._t = threading.Thread(target=self.loop)
9                 _t.start()
10         
11         def stop (self):
12                 self._running = False
13         
14         def loop (self):
15                 while self._running:
16                         if (self.state_to_set is not None):
17                                 if self.state_to_set != self.state_last_set:
18                                         stts = self.state_to_set # cache for parallelism
19                                         error = do_request(stts) # TODO
20                                         #TODO logging
21                                         if not error:
22                                                 self.state_last_set = stts
23                                                 #TODO logging
24                         time.sleep(SPACE_API_LOOP_DELAY)