def _unsubscribe_async(self, topic, ack_callback=None): self._subscription_manager.remove_record(topic) rc, mid = self._internal_async_client.unsubscribe(topic, ack_callback) if MQTT_ERR_SUCCESS != rc: self._logger.error("Unsubscribe error: %d", rc) raise unsubscribeError(rc) return rc, mid
def unsubscribe(self, topic): if (topic is None): self._log.error("unsubscribe: None type inputs detected.") raise TypeError("None type inputs detected.") self._log.debug("unsubscribe from: " + topic) # Return unsubscribe succeeded/failed ret = False self._unsubscribeLock.acquire() # Unsubscribe (rc, mid) = self._pahoClient.unsubscribe(topic) # Throw exception... self._log.debug("Started an unsubscribe request " + str(mid)) TenmsCount = 0 while (TenmsCount != self._mqttOperationTimeout * 100 and not self._unsubscribeSent): TenmsCount += 1 time.sleep(0.01) if (self._unsubscribeSent): ret = rc == 0 if (ret): try: del self._subscribePool[topic] except KeyError: pass # Ignore topics that are never subscribed to self._log.debug("Unsubscribe request " + str(mid) + " succeeded. Time consumption: " + str(float(TenmsCount) * 10) + "ms.") self._pahoClient.message_callback_remove(topic) self._log.debug("Remove the callback.") else: self._log.error("Unsubscribe request " + str(mid) + " failed with code: " + str(rc)) self._unsubscribeLock.release( ) # Release the lock when exception is raised raise unsubscribeError(rc) else: # Unsubscribe timeout self._log.error("No feedback detected for unsubscribe request " + str(mid) + ". Timeout and failed.") self._unsubscribeLock.release( ) # Release the lock when exception is raised raise unsubscribeTimeoutException() self._unsubscribeSent = False self._log.debug( "Recover unsubscribe context for the next request: unsubscribeSent: " + str(self._unsubscribeSent)) self._unsubscribeLock.release() return ret
def unsubscribe(self, topic): if(topic is None): self._log.error("unsubscribe: None type inputs detected.") raise TypeError("None type inputs detected.") self._log.debug("unsubscribe from: " + topic) # Return unsubscribe succeeded/failed ret = False self._unsubscribeLock.acquire() # Unsubscribe (rc, mid) = self._pahoClient.unsubscribe(topic) # Throw exception... self._log.debug("Started an unsubscribe request " + str(mid)) TenmsCount = 0 while(TenmsCount != self._mqttOperationTimeout * 100 and not self._unsubscribeSent): TenmsCount += 1 time.sleep(0.01) if(self._unsubscribeSent): ret = rc == 0 if(ret): try: del self._subscribePool[topic] except KeyError: pass # Ignore topics that are never subscribed to self._log.debug("Unsubscribe request " + str(mid) + " succeeded. Time consumption: " + str(float(TenmsCount) * 10) + "ms.") self._pahoClient.message_callback_remove(topic) self._log.debug("Remove the callback.") else: self._log.error("Unsubscribe request " + str(mid) + " failed with code: " + str(rc)) self._unsubscribeLock.release() # Release the lock when exception is raised raise unsubscribeError(rc) else: # Unsubscribe timeout self._log.error("No feedback detected for unsubscribe request " + str(mid) + ". Timeout and failed.") self._unsubscribeLock.release() # Release the lock when exception is raised raise unsubscribeTimeoutException() self._unsubscribeSent = False self._log.debug("Recover unsubscribe context for the next request: unsubscribeSent: " + str(self._unsubscribeSent)) self._unsubscribeLock.release() return ret