Add is_receiving:

This commit is contained in:
Lorenz Diener 2018-04-17 14:59:45 +02:00
pare 6d4490295a
commit eb336a30c2

Veure arxiu

@ -1716,6 +1716,7 @@ class Mastodon:
self.connect_func = connect_func self.connect_func = connect_func
self.reconnect_async = reconnect_async self.reconnect_async = reconnect_async
self.reconnect_async_wait_sec = reconnect_async_wait_sec self.reconnect_async_wait_sec = reconnect_async_wait_sec
self.reconnecting = False
def close(self): def close(self):
self.closed = True self.closed = True
@ -1724,6 +1725,12 @@ class Mastodon:
def is_alive(self): def is_alive(self):
return self._thread.is_alive() return self._thread.is_alive()
def is_receiving(self):
if self.closed or not self.running or self.reconnecting or not self.is_alive():
return False
else:
return True
def _threadproc(self): def _threadproc(self):
self._thread = threading.current_thread() self._thread = threading.current_thread()
@ -1741,6 +1748,7 @@ class Mastodon:
# Reconnect loop. Try immediately once, then with delays on error. # Reconnect loop. Try immediately once, then with delays on error.
if self.reconnect_async and not self.closed: if self.reconnect_async and not self.closed:
self.reconnecting = True
connect_success = False connect_success = False
while not connect_success: while not connect_success:
connect_success = True connect_success = True
@ -1752,7 +1760,7 @@ class Mastodon:
except: except:
time.sleep(self.reconnect_async_wait_sec) time.sleep(self.reconnect_async_wait_sec)
connect_success = False connect_success = False
self.reconnecting = False
else: else:
self.running = False self.running = False
return 0 return 0