umqtt.robust: Add universal with_retry method, and publish_() using it.

This method uses more memory though.
mqtt
Paul Sokolovsky 2016-06-05 14:35:33 +03:00
rodzic 4dc1f1c264
commit d3d0b4f0b5
1 zmienionych plików z 12 dodań i 0 usunięć

Wyświetl plik

@ -26,6 +26,18 @@ class MQTTClient(simple.MQTTClient):
i += 1
self.delay(i)
def with_retry(self, meth, *args, **kwargs):
while 1:
try:
return meth(*args, **kwargs)
except OSError as e:
print("%r" % e)
time.sleep(0.5)
self.reconnect()
def publish_(self, *args, **kwargs):
return self.with_retry(super().publish, *args, **kwargs)
def publish(self, topic, msg, retain=False, qos=0):
while 1:
try: