diff options
author | Tom Nichols <tmnichols@gmail.com> | 2010-07-02 12:57:27 -0400 |
---|---|---|
committer | Tom Nichols <tmnichols@gmail.com> | 2010-07-02 12:57:27 -0400 |
commit | 661cdd2018d0bca57c0f6e4bd0d69e8cc6754c05 (patch) | |
tree | a1f02a9dcc1bdf75cbfed6db60a73af05d09586a | |
parent | 62da57a6c26a16024dd481b364e5d1021bc3dd3b (diff) | |
download | slixmpp-661cdd2018d0bca57c0f6e4bd0d69e8cc6754c05.tar.gz slixmpp-661cdd2018d0bca57c0f6e4bd0d69e8cc6754c05.tar.bz2 slixmpp-661cdd2018d0bca57c0f6e4bd0d69e8cc6754c05.tar.xz slixmpp-661cdd2018d0bca57c0f6e4bd0d69e8cc6754c05.zip |
'wait' could delay longer than desired if waiting threads were notified but did not achieve their lock condition afterwards.
-rw-r--r-- | sleekxmpp/xmlstream/statemachine.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/sleekxmpp/xmlstream/statemachine.py b/sleekxmpp/xmlstream/statemachine.py index 9412d5ad..dc54bb88 100644 --- a/sleekxmpp/xmlstream/statemachine.py +++ b/sleekxmpp/xmlstream/statemachine.py @@ -86,8 +86,9 @@ class StateMachine(object): start = time.time() while not self.__current_state in from_states or not self.lock.acquire(False): # detect timeout: - if time.time() >= start + wait: return False - self.notifier.wait(wait) + remainder = start + wait - time.time() + if remainder > 0: self.notifier.wait(remainder) + else: return False try: # lock is acquired; all other threads will return false or wait until notify/timeout self.notifier.clear() @@ -180,8 +181,9 @@ class StateMachine(object): start = time.time() while not self.__current_state in states: # detect timeout: - if time.time() >= start + wait: return False - self.notifier.wait(wait) + remainder = start + wait - time.time() + if remainder > 0: self.notifier.wait(remainder) + else: return False return True @@ -227,10 +229,11 @@ class _StateCtx: start = time.time() while not self.state_machine[ self.from_state ] or not self.state_machine.lock.acquire(False): # detect timeout: - if time.time() >= start + self.wait: + remainder = start + self.wait - time.time() + if remainder > 0: self.state_machine.notifier.wait(remainder) + else: log.debug('StateMachine timeout while waiting for state: %s', self.from_state ) return False - self.state_machine.notifier.wait(self.wait) self._locked = True # lock has been acquired at this point self.state_machine.notifier.clear() |