Skip to content

Commit 0335d0a

Browse files
committed
v1.2 changes
1 parent 057fda5 commit 0335d0a

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

AWSIoTPythonSDK/core/protocol/paho/client.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@
4949
from AWSIoTPythonSDK.core.protocol.connection.cores import SecuredWebSocketCore
5050
from AWSIoTPythonSDK.core.protocol.connection.alpn import SSLContextBuilder
5151

52-
VERSION_MAJOR=1
53-
VERSION_MINOR=0
54-
VERSION_REVISION=0
55-
VERSION_NUMBER=(VERSION_MAJOR*1000000+VERSION_MINOR*1000+VERSION_REVISION)
56-
5752
MQTTv31 = 3
5853
MQTTv311 = 4
5954

@@ -924,6 +919,9 @@ def loop(self, timeout=1.0, max_packets=1):
924919
# Can occur if we just reconnected but rlist/wlist contain a -1 for
925920
# some reason.
926921
return MQTT_ERR_CONN_LOST
922+
except KeyboardInterrupt:
923+
# Allow ^C to interrupt
924+
raise
927925
except:
928926
return MQTT_ERR_UNKNOWN
929927

@@ -981,6 +979,9 @@ def publish(self, topic, payload=None, qos=0, retain=False):
981979
raise ValueError('Invalid QoS level.')
982980
if isinstance(payload, str) or isinstance(payload, bytearray):
983981
local_payload = payload
982+
# Client.publish() now accepts bytes() payloads on Python 3.
983+
elif sys.version_info[0] == 3 and isinstance(payload, bytes):
984+
local_payload = bytearray(payload)
984985
elif sys.version_info[0] < 3 and isinstance(payload, unicode):
985986
local_payload = payload
986987
elif isinstance(payload, int) or isinstance(payload, float):
@@ -1117,7 +1118,8 @@ def subscribe(self, topic, qos=0):
11171118
zero string length, or if topic is not a string, tuple or list.
11181119
"""
11191120
topic_qos_list = None
1120-
if isinstance(topic, str):
1121+
# Client.subscribe() now accepts unicode type topic inputs on Python 2
1122+
if isinstance(topic, str) or (sys.version_info[0] == 2 and isinstance(topic, unicode)):
11211123
if qos<0 or qos>2:
11221124
raise ValueError('Invalid QoS level.')
11231125
if topic is None or len(topic) == 0:
@@ -1165,7 +1167,8 @@ def unsubscribe(self, topic):
11651167
topic_list = None
11661168
if topic is None:
11671169
raise ValueError('Invalid topic.')
1168-
if isinstance(topic, str):
1170+
# Client.unsubscribe() now accepts unicode type topic inputs on Python 2
1171+
if isinstance(topic, str) or (sys.version_info[0] == 2 and isinstance(topic, unicode)):
11691172
if len(topic) == 0:
11701173
raise ValueError('Invalid topic.')
11711174
topic_list = [topic.encode('utf-8')]
@@ -1453,8 +1456,10 @@ def loop_stop(self, force=False):
14531456
return MQTT_ERR_INVAL
14541457

14551458
self._thread_terminate = True
1456-
self._thread.join()
1457-
self._thread = None
1459+
# Don't attempt to join() own thread.
1460+
if threading.current_thread() != self._thread:
1461+
self._thread.join()
1462+
self._thread = None
14581463

14591464
def message_callback_add(self, sub, callback):
14601465
"""Register a message callback for a specific topic.
@@ -1704,6 +1709,10 @@ def _easy_log(self, level, buf):
17041709
self.on_log(self, self._userdata, level, buf)
17051710

17061711
def _check_keepalive(self):
1712+
# Fix for keepalive=0 causing an infinite disconnect/reconnect loop.
1713+
if self._keepalive == 0:
1714+
return MQTT_ERR_SUCCESS
1715+
17071716
now = time.time()
17081717
self._msgtime_mutex.acquire()
17091718
last_msg_out = self._last_msg_out

0 commit comments

Comments
 (0)