cleaner syntax for thread lock
This commit is contained in:
parent
4183309c12
commit
d6356bbfc5
|
@ -191,15 +191,12 @@ class StateMachine:
|
||||||
self.currentState.entry()
|
self.currentState.entry()
|
||||||
|
|
||||||
def selectState(self, signal):
|
def selectState(self, signal):
|
||||||
self._lock.acquire() # make state transitions threadsafe
|
with self._lock
|
||||||
try:
|
|
||||||
nextState = self.currentState.next(signal)
|
nextState = self.currentState.next(signal)
|
||||||
if nextState != self.currentState:
|
if nextState != self.currentState:
|
||||||
self.currentState.exit()
|
self.currentState.exit()
|
||||||
self.currentState = nextState
|
self.currentState = nextState
|
||||||
self.currentState.entry()
|
self.currentState.entry()
|
||||||
finally:
|
|
||||||
self._lock.release()
|
|
||||||
|
|
||||||
self._cfg['state'] = self.currentState.name
|
self._cfg['state'] = self.currentState.name
|
||||||
self._cfg.sync()
|
self._cfg.sync()
|
||||||
|
|
Loading…
Reference in New Issue