Skip to content

Commit

Permalink
Clean mqtt client shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
titilambert committed Sep 4, 2017
1 parent 377c6d5 commit 980b0de
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tuxeatpi_common/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MqttClient(paho.Client):

def __init__(self, component):
paho.Client.__init__(self, clean_session=True, userdata=component.name)
self._must_run = True
self.component = component
self.topics = {}
self.logger = logging.getLogger(name="tep").getChild(component.name).getChild('mqttclient')
Expand Down Expand Up @@ -88,7 +89,7 @@ def on_publish(self, client, userdata, mid): # pylint: disable=W0221,W0613
def run(self):
"""Run MQTT client"""
# TODO handle reconnect
while True:
while self._must_run:
try:
self.connect(self.host, self.port, 60)
break
Expand All @@ -103,6 +104,7 @@ def run(self):

def stop(self):
"""Stop MQTT client"""
self._must_run = False
self.loop_stop()
self.disconnect()

Expand Down

0 comments on commit 980b0de

Please sign in to comment.