Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

trying to get the mess sorted out...

  • Loading branch information...
commit e3146fd4f484ef08bb919447a1a4dbff14fa5190 1 parent 83a12e4
@rep authored
Showing with 23 additions and 8 deletions.
  1. +23 −8 lib/hpfeeds.py
View
31 lib/hpfeeds.py
@@ -69,6 +69,7 @@ def __init__(self, host, port, ident, secret, timeout=3, reconnect=True, sleepwa
self.connected = False
self.stopped = False
self.s = None
+ self.subscriptions = set()
self.unpacker = FeedUnpack()
self.tryconnect()
@@ -184,12 +185,12 @@ def run(self, message_callback, error_callback):
# end run loops if stopped
if self.stopped: break
- if self.stopped:
- logger.info('Stopped, exiting run loop.')
- break
- # connect again if disconnected
- self.tryconnect()
+ if not self.stopped and self.reconnect:
+ # connect again if disconnected
+ self.tryconnect()
+
+ logger.info('Stopped, exiting run loop.')
def wait(self, timeout=1):
self.s.settimeout(timeout)
@@ -213,19 +214,33 @@ def subscribe(self, chaninfo):
if type(chaninfo) == str:
chaninfo = [chaninfo,]
for c in chaninfo:
- self.send(msgsubscribe(self.ident, c))
+ self.subscriptions.add(c)
+ try:
+ self.send(msgsubscribe(self.ident, c))
+ except Disconnect:
+ self.connected = False
+ logger.info('Disconnected from broker (in subscribe).')
+ if not self.reconnect: raise
+ break
+
def publish(self, chaninfo, data):
if type(chaninfo) == str:
chaninfo = [chaninfo,]
for c in chaninfo:
- self.send(msgpublish(self.ident, c, data))
+ try:
+ self.send(msgpublish(self.ident, c, data))
+ except Disconnect:
+ self.connected = False
+ logger.info('Disconnected from broker (in publish).')
+ if not self.reconnect: raise
+ break
def stop(self):
self.stopped = True
def close(self):
try: self.s.close()
- except: logger.warn('Socket exception when closing.')
+ except: logger.debug('Socket exception when closing (ignored though).')
def new(host=None, port=10000, ident=None, secret=None, timeout=3, reconnect=True, sleepwait=20):
Please sign in to comment.
Something went wrong with that request. Please try again.