cleaner syntax for thread lock

This commit is contained in:
petrucci4prez 2017-06-03 16:02:21 -04:00
parent 4183309c12
commit d6356bbfc5
1 changed files with 1 additions and 4 deletions

View File

@ -191,15 +191,12 @@ class StateMachine:
self.currentState.entry()
def selectState(self, signal):
self._lock.acquire() # make state transitions threadsafe
try:
with self._lock
nextState = self.currentState.next(signal)
if nextState != self.currentState:
self.currentState.exit()
self.currentState = nextState
self.currentState.entry()
finally:
self._lock.release()
self._cfg['state'] = self.currentState.name
self._cfg.sync()