Correct the statemachine's ensure_any method.
It had not been updated to use the new condition instead of the old threading event.
This commit is contained in:
parent
83c5a4cd2f
commit
aedbecd673
2 changed files with 5 additions and 13 deletions
13
sleekxmpp/thirdparty/statemachine.py
vendored
13
sleekxmpp/thirdparty/statemachine.py
vendored
|
@ -188,16 +188,7 @@ class StateMachine(object):
|
||||||
# avoid an operation occurring in the wrong state.
|
# avoid an operation occurring in the wrong state.
|
||||||
# TODO another option would be an ensure_ctx that uses a semaphore to allow
|
# TODO another option would be an ensure_ctx that uses a semaphore to allow
|
||||||
# threads to indicate they want to remain in a particular state.
|
# threads to indicate they want to remain in a particular state.
|
||||||
|
self.lock.acquire()
|
||||||
# will return immediately if no transition is in process.
|
|
||||||
if block_on_transition:
|
|
||||||
# we're not in the middle of a transition; don't hold the lock
|
|
||||||
if self.lock.acquire(False):
|
|
||||||
self.lock.release()
|
|
||||||
# wait for the transition to complete
|
|
||||||
else:
|
|
||||||
self.lock.wait()
|
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
while not self.__current_state in states:
|
while not self.__current_state in states:
|
||||||
# detect timeout:
|
# detect timeout:
|
||||||
|
@ -205,7 +196,9 @@ class StateMachine(object):
|
||||||
if remainder > 0:
|
if remainder > 0:
|
||||||
self.lock.wait(remainder)
|
self.lock.wait(remainder)
|
||||||
else:
|
else:
|
||||||
|
self.lock.release()
|
||||||
return False
|
return False
|
||||||
|
self.lock.release()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
|
|
@ -1234,9 +1234,8 @@ class XMLStream(object):
|
||||||
# be resent and processing will resume.
|
# be resent and processing will resume.
|
||||||
while not self.stop.is_set():
|
while not self.stop.is_set():
|
||||||
# Only process the stream while connected to the server
|
# Only process the stream while connected to the server
|
||||||
if not self.state.ensure('connected', wait=0.1,
|
if not self.state.ensure('connected', wait=0.1):
|
||||||
block_on_transition=True):
|
break
|
||||||
continue
|
|
||||||
# Ensure the stream header is sent for any
|
# Ensure the stream header is sent for any
|
||||||
# new connections.
|
# new connections.
|
||||||
if not self.session_started_event.is_set():
|
if not self.session_started_event.is_set():
|
||||||
|
|
Loading…
Reference in a new issue