Remove ability to control the listening loop externally
It was probably scarcely used, and separate functionality will be developed that makes this redundant anyhow.
This commit is contained in:
@@ -43,12 +43,6 @@ class Client:
|
|||||||
to provide custom event handling (mainly useful while listening).
|
to provide custom event handling (mainly useful while listening).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
listening = False
|
|
||||||
"""Whether the client is listening.
|
|
||||||
|
|
||||||
Used when creating an external event loop to determine when to stop listening.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def uid(self):
|
def uid(self):
|
||||||
"""The ID of the client.
|
"""The ID of the client.
|
||||||
@@ -2694,23 +2688,7 @@ class Client:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.onMessageError(exception=e, msg=m)
|
self.onMessageError(exception=e, msg=m)
|
||||||
|
|
||||||
def startListening(self):
|
def _doOneListen(self):
|
||||||
"""Start listening from an external event loop.
|
|
||||||
|
|
||||||
Raises:
|
|
||||||
FBchatException: If request failed
|
|
||||||
"""
|
|
||||||
self.listening = True
|
|
||||||
|
|
||||||
def doOneListen(self):
|
|
||||||
"""Do one cycle of the listening loop.
|
|
||||||
|
|
||||||
This method is useful if you want to control the client from an external event
|
|
||||||
loop.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
bool: Whether the loop should keep running
|
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
if self._markAlive:
|
if self._markAlive:
|
||||||
self._ping()
|
self._ping()
|
||||||
@@ -2729,7 +2707,6 @@ class Client:
|
|||||||
if e.request_status_code in [502, 503]:
|
if e.request_status_code in [502, 503]:
|
||||||
# Bump pull channel, while contraining withing 0-4
|
# Bump pull channel, while contraining withing 0-4
|
||||||
self._pull_channel = (self._pull_channel + 1) % 5
|
self._pull_channel = (self._pull_channel + 1) % 5
|
||||||
self.startListening()
|
|
||||||
else:
|
else:
|
||||||
raise e
|
raise e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@@ -2737,11 +2714,6 @@ class Client:
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def stopListening(self):
|
|
||||||
"""Clean up the variables from `Client.startListening`."""
|
|
||||||
self.listening = False
|
|
||||||
self._sticky, self._pool = (None, None)
|
|
||||||
|
|
||||||
def listen(self, markAlive=None):
|
def listen(self, markAlive=None):
|
||||||
"""Initialize and runs the listening loop continually.
|
"""Initialize and runs the listening loop continually.
|
||||||
|
|
||||||
@@ -2751,13 +2723,12 @@ class Client:
|
|||||||
if markAlive is not None:
|
if markAlive is not None:
|
||||||
self.setActiveStatus(markAlive)
|
self.setActiveStatus(markAlive)
|
||||||
|
|
||||||
self.startListening()
|
|
||||||
self.onListening()
|
self.onListening()
|
||||||
|
|
||||||
while self.listening and self.doOneListen():
|
while self._doOneListen():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.stopListening()
|
self._sticky, self._pool = (None, None)
|
||||||
|
|
||||||
def setActiveStatus(self, markAlive):
|
def setActiveStatus(self, markAlive):
|
||||||
"""Change active status while listening.
|
"""Change active status while listening.
|
||||||
|
@@ -39,22 +39,20 @@ TEXT_LIST = [
|
|||||||
|
|
||||||
|
|
||||||
class ClientThread(threading.Thread):
|
class ClientThread(threading.Thread):
|
||||||
|
# TODO: Refactor this to work with the new listening setup
|
||||||
def __init__(self, client, *args, **kwargs):
|
def __init__(self, client, *args, **kwargs):
|
||||||
self.client = client
|
self.client = client
|
||||||
self.should_stop = threading.Event()
|
self.should_stop = threading.Event()
|
||||||
super(ClientThread, self).__init__(*args, **kwargs)
|
super(ClientThread, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.client.startListening()
|
self.client._doOneListen() # QPrimer, Facebook now knows we're about to start pulling
|
||||||
self.client.doOneListen() # QPrimer, Facebook now knows we're about to start pulling
|
|
||||||
super(ClientThread, self).start()
|
super(ClientThread, self).start()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while not self.should_stop.is_set() and self.client.doOneListen():
|
while not self.should_stop.is_set() and self.client._doOneListen():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self.client.stopListening()
|
|
||||||
|
|
||||||
|
|
||||||
class CaughtValue(threading.Event):
|
class CaughtValue(threading.Event):
|
||||||
def set(self, res):
|
def set(self, res):
|
||||||
|
Reference in New Issue
Block a user