From d6356bbfc5763c993e6c180219baf8f818da3abb Mon Sep 17 00:00:00 2001 From: petrucci4prez Date: Sat, 3 Jun 2017 16:02:21 -0400 Subject: [PATCH] cleaner syntax for thread lock --- stateMachine.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/stateMachine.py b/stateMachine.py index e692136..b46768c 100644 --- a/stateMachine.py +++ b/stateMachine.py @@ -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()