aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2018-04-17 14:59:45 +0200
committerLorenz Diener <[email protected]>2018-04-17 14:59:45 +0200
commiteb336a30c2ef04c2b0f66727de1bc585ad96e2da (patch)
treec39803aa6a1ed99c78fe1e8cacd687d541426a82
parent6d4490295a7371da1939efd612f919b6ce6af3d3 (diff)
downloadmastodon.py-eb336a30c2ef04c2b0f66727de1bc585ad96e2da.tar.gz
Add is_receiving:
-rw-r--r--mastodon/Mastodon.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 595b79e..3706008 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1716,6 +1716,7 @@ class Mastodon:
1716 self.connect_func = connect_func 1716 self.connect_func = connect_func
1717 self.reconnect_async = reconnect_async 1717 self.reconnect_async = reconnect_async
1718 self.reconnect_async_wait_sec = reconnect_async_wait_sec 1718 self.reconnect_async_wait_sec = reconnect_async_wait_sec
1719 self.reconnecting = False
1719 1720
1720 def close(self): 1721 def close(self):
1721 self.closed = True 1722 self.closed = True
@@ -1724,6 +1725,12 @@ class Mastodon:
1724 def is_alive(self): 1725 def is_alive(self):
1725 return self._thread.is_alive() 1726 return self._thread.is_alive()
1726 1727
1728 def is_receiving(self):
1729 if self.closed or not self.running or self.reconnecting or not self.is_alive():
1730 return False
1731 else:
1732 return True
1733
1727 def _threadproc(self): 1734 def _threadproc(self):
1728 self._thread = threading.current_thread() 1735 self._thread = threading.current_thread()
1729 1736
@@ -1741,6 +1748,7 @@ class Mastodon:
1741 1748
1742 # Reconnect loop. Try immediately once, then with delays on error. 1749 # Reconnect loop. Try immediately once, then with delays on error.
1743 if self.reconnect_async and not self.closed: 1750 if self.reconnect_async and not self.closed:
1751 self.reconnecting = True
1744 connect_success = False 1752 connect_success = False
1745 while not connect_success: 1753 while not connect_success:
1746 connect_success = True 1754 connect_success = True
@@ -1752,7 +1760,7 @@ class Mastodon:
1752 except: 1760 except:
1753 time.sleep(self.reconnect_async_wait_sec) 1761 time.sleep(self.reconnect_async_wait_sec)
1754 connect_success = False 1762 connect_success = False
1755 1763 self.reconnecting = False
1756 else: 1764 else:
1757 self.running = False 1765 self.running = False
1758 return 0 1766 return 0
Powered by cgit v1.2.3 (git 2.41.0)