Skip to content

Commit 08880c2

Browse files
committed
Updated hub
Signed-off-by: Vishal Rana <vr@labstack.com>
1 parent 7da6aca commit 08880c2

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

labstack/hub.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import signal
21
import time
32
import paho.mqtt.client as mqtt
43

@@ -12,15 +11,13 @@ def __init__(self, account_id, api_key, client_id=None):
1211
def handler(client, userdata, msg):
1312
self.handlers[msg.topic](msg.payload)
1413
self.client.on_message = handler
15-
self._run = True
16-
signal.signal(signal.SIGINT, self._stop)
17-
signal.signal(signal.SIGTERM, self._stop)
1814

1915
def connect(self, handler=None):
2016
self.client.connect("hub.labstack.com", 1883)
2117
self.client.loop_start()
2218
def on_connect(client, userdata, flags, rc):
23-
handler()
19+
if handler is not None:
20+
handler()
2421
self.client.on_connect = on_connect
2522

2623
def publish(self, topic, message):
@@ -42,9 +39,8 @@ def disconnect(self):
4239
self.client.disconnect()
4340

4441
def run(self):
45-
while self._run:
46-
time.sleep(1)
47-
48-
def _stop(self, signum, frame):
49-
self._run = False
50-
self.disconnect()
42+
try:
43+
while True:
44+
time.sleep(1)
45+
except (KeyboardInterrupt):
46+
pass

0 commit comments

Comments
 (0)