summaryrefslogtreecommitdiff
path: root/sleekxmpp/thirdparty
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-08-10 14:15:55 -0700
committerLance Stout <lancestout@gmail.com>2012-08-10 14:15:55 -0700
commit962dfad2166574955c7be6d12c930991b0f29403 (patch)
tree6a4dd01bd7668bb133814d0e099fed38ef7d08d7 /sleekxmpp/thirdparty
parent14aa8311690f3a58ff4b7ad286bcccdd867789f7 (diff)
parentf7a710e55bf433a378dee4bd05f6ceb59f2e9e2d (diff)
downloadslixmpp-962dfad2166574955c7be6d12c930991b0f29403.tar.gz
slixmpp-962dfad2166574955c7be6d12c930991b0f29403.tar.bz2
slixmpp-962dfad2166574955c7be6d12c930991b0f29403.tar.xz
slixmpp-962dfad2166574955c7be6d12c930991b0f29403.zip
Merge branch 'master' into develop
Diffstat (limited to 'sleekxmpp/thirdparty')
-rw-r--r--sleekxmpp/thirdparty/statemachine.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/sleekxmpp/thirdparty/statemachine.py b/sleekxmpp/thirdparty/statemachine.py
index 33d9b828..4b5ecd6b 100644
--- a/sleekxmpp/thirdparty/statemachine.py
+++ b/sleekxmpp/thirdparty/statemachine.py
@@ -29,7 +29,7 @@ class StateMachine(object):
if state in self.__states:
raise IndexError("The state '%s' is already in the StateMachine." % state)
self.__states.append(state)
- finally:
+ finally:
self.lock.release()
@@ -83,11 +83,14 @@ class StateMachine(object):
if not to_state in self.__states:
raise ValueError("StateMachine does not contain to_state %s." % to_state)
+ if self.__current_state == to_state:
+ return True
+
start = time.time()
while not self.lock.acquire(False):
time.sleep(.001)
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
while not self.__current_state in from_states:
@@ -108,7 +111,7 @@ class StateMachine(object):
# some 'false' value returned from func,
# indicating that transition should not occur:
- if not return_val:
+ if not return_val:
return return_val
log.debug(' ==== TRANSITION %s -> %s', self.__current_state, to_state)
@@ -193,9 +196,9 @@ class StateMachine(object):
while not self.__current_state in states:
# detect timeout:
remainder = start + wait - time.time()
- if remainder > 0:
+ if remainder > 0:
self.lock.wait(remainder)
- else:
+ else:
self.lock.release()
return False
self.lock.release()
@@ -241,7 +244,7 @@ class _StateCtx:
while not self.state_machine[self.from_state] or not self.state_machine.lock.acquire(False):
# detect timeout:
remainder = start + self.wait - time.time()
- if remainder > 0:
+ if remainder > 0:
self.state_machine.lock.wait(remainder)
else:
log.debug('StateMachine timeout while waiting for state: %s', self.from_state)