Fix handling state machine lock when quick exiting.

This commit is contained in:
Lance Stout 2012-08-10 14:11:44 -07:00
parent 230465b946
commit 814a50e36f

View File

@ -83,16 +83,16 @@ class StateMachine(object):
if not to_state in self.__states: if not to_state in self.__states:
raise ValueError("StateMachine does not contain to_state %s." % to_state) raise ValueError("StateMachine does not contain to_state %s." % to_state)
if self.__current_state == to_state:
return True
start = time.time() start = time.time()
while not self.lock.acquire(False): while not self.lock.acquire(False):
time.sleep(.001) time.sleep(.001)
if (start + wait - time.time()) <= 0.0: if (start + wait - time.time()) <= 0.0:
log.debug("Could not acquire lock") log.debug("==== Could not acquire lock in %s sec: %s -> %s ", wait, self.__current_state, to_state)
return False return False
if self.__current_state == to_state:
return True
while not self.__current_state in from_states: while not self.__current_state in from_states:
# detect timeout: # detect timeout:
remainder = start + wait - time.time() remainder = start + wait - time.time()