|
59 | 59 | from queue import Queue |
60 | 60 |
|
61 | 61 |
|
62 | | -class AckPacket(object): |
| 62 | +class SubackPacket(object): |
63 | 63 | def __init__(self): |
64 | 64 | self.event = Event() |
65 | 65 | self.data = None |
@@ -305,15 +305,15 @@ def subscribe(self, topic, qos, message_callback=None): |
305 | 305 | if ClientStatus.STABLE != self._client_status.get_status(): |
306 | 306 | self._handle_offline_request(RequestTypes.SUBSCRIBE, (topic, qos, message_callback, None)) |
307 | 307 | else: |
308 | | - ack = AckPacket() |
309 | | - rc, mid = self._subscribe_async(topic, qos, self._create_blocking_ack_callback_ret(ack), message_callback) |
310 | | - if not ack.event.wait(self._operation_timeout_sec): |
| 308 | + suback = SubackPacket() |
| 309 | + rc, mid = self._subscribe_async(topic, qos, self._create_blocking_suback_callback(suback), message_callback) |
| 310 | + if not suback.event.wait(self._operation_timeout_sec): |
311 | 311 | self._internal_async_client.remove_event_callback(mid) |
312 | 312 | self._logger.error("Subscribe timed out") |
313 | 313 | raise subscribeTimeoutException() |
314 | | - if ack.data[0] == MQTT_ERR_SUBACK_ERROR: |
315 | | - self._logger.error(f"Subscribe error: {ack.data}") |
316 | | - raise subscribeError(ack.data) |
| 314 | + if suback.data and suback.data[0] == MQTT_ERR_SUBACK_ERROR: |
| 315 | + self._logger.error(f"Subscribe error: {suback.data}") |
| 316 | + raise subscribeError(suback.data) |
317 | 317 | ret = True |
318 | 318 | return ret |
319 | 319 |
|
@@ -371,7 +371,7 @@ def ack_callback(mid, data=None): |
371 | 371 | event.set() |
372 | 372 | return ack_callback |
373 | 373 |
|
374 | | - def _create_blocking_ack_callback_ret(self, ack: AckPacket): |
| 374 | + def _create_blocking_suback_callback(self, ack: SubackPacket): |
375 | 375 | def ack_callback(mid, data=None): |
376 | 376 | ack.data = data |
377 | 377 | ack.event.set() |
|
0 commit comments