- # check if there's something we need to do
- if self._state_last_set == self._state_to_set: return
- # take action!
- error = do_request(stts) # TODO
- #TODO logging
- if not error:
- self.state_last_set = stts
+ else:
+ # always have a local variable because of parallelism
+ state = self._state_to_set
+
+ if not self._set_state_lock.acquire(False):
+ # we don't want many threads to wait here
+ # the next status update will fix everything anyways
+ pass
+ else:
+ # got the lock
+ try:
+ # check if there's something we need to do
+ if self._state_last_set == state: return
+ # take action!
+ error = do_request(stts) # TODO
+ #TODO logging
+ #TODO error too often -> log critical to send mails
+ if not error:
+ self.state_last_set = stts
+ finally:
+ self._set_state_lock.release()