Skip to content

Commit 731782c

Browse files
committed
Make sure write queue tasks are marked as done.
1 parent 4a09a77 commit 731782c

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

myDevices/cloud/client.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,24 @@ def run(self):
110110
if self.cloudClient.mqttClient.connected == False:
111111
info('WriterThread mqttClient not connected')
112112
continue
113+
got_packet = False
113114
topic, message = self.cloudClient.DequeuePacket()
114-
if message:
115-
# debug('WriterThread, topic: {} {}'.format(topic, message))
116-
if not isinstance(message, str):
117-
message = dumps(message)
118-
self.cloudClient.mqttClient.publish_packet(topic, message)
119-
message = None
120-
self.cloudClient.writeQueue.task_done()
115+
if topic or message:
116+
got_packet = True
117+
try:
118+
if message:
119+
# debug('WriterThread, topic: {} {}'.format(topic, message))
120+
if not isinstance(message, str):
121+
message = dumps(message)
122+
self.cloudClient.mqttClient.publish_packet(topic, message)
123+
message = None
124+
except:
125+
exception("WriterThread publish packet error")
126+
finally:
127+
if got_packet:
128+
self.cloudClient.writeQueue.task_done()
121129
except:
122-
exception("WriterThread Unexpected error")
130+
exception("WriterThread unexpected error")
123131
return
124132

125133
def stop(self):
@@ -405,6 +413,7 @@ def ProcessPowerCommand(self, message):
405413
cayennemqtt.DataChannel.add(data, message['channel'], value=1)
406414
self.EnqueuePacket(data)
407415
self.writeQueue.join()
416+
info('Calling execute: {}'.format(commands[message['channel']]))
408417
output, result = executeCommand(commands[message['channel']])
409418
debug('ProcessPowerCommand: {}, result: {}, output: {}'.format(message, result, output))
410419
if result != 0:

0 commit comments

Comments
 (0)