summaryrefslogtreecommitdiff
path: root/sleekxmpp
diff options
context:
space:
mode:
authorTom Nichols <tmnichols@gmail.com>2010-07-02 12:57:27 -0400
committerTom Nichols <tmnichols@gmail.com>2010-07-02 12:57:27 -0400
commit661cdd2018d0bca57c0f6e4bd0d69e8cc6754c05 (patch)
treea1f02a9dcc1bdf75cbfed6db60a73af05d09586a /sleekxmpp
parent62da57a6c26a16024dd481b364e5d1021bc3dd3b (diff)
downloadslixmpp-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.
Diffstat (limited to 'sleekxmpp')
-rw-r--r--sleekxmpp/xmlstream/statemachine.py15
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()