From ae9c41e29db61cc67e5e5bac39892182fa9c00ca Mon Sep 17 00:00:00 2001 From: Nick Veys Date: Thu, 10 Nov 2011 09:34:56 -0600 Subject: [PATCH 1/2] Fixing 'duration' keyword in Python example --- python/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/README b/python/README index c20eb706..c1e275d6 100644 --- a/python/README +++ b/python/README @@ -58,7 +58,7 @@ analytics = pubnub.analytics({ 'channel' : 'channel-name-here', ## Leave blank for all channels 'limit' : 100, ## aggregation range 'ago' : 0, ## minutes ago to look backward - 'duratoin' : 100 ## minutes offset + 'duration' : 100 ## minutes offset }) print(analytics) From b7f85d34717a75a66111dedc2cc43b9e1d7244b1 Mon Sep 17 00:00:00 2001 From: Nick Veys Date: Thu, 10 Nov 2011 09:39:02 -0600 Subject: [PATCH 2/2] Switching from recursive to iterative subscribe strategy --- python/Pubnub.py | 58 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/python/Pubnub.py b/python/Pubnub.py index 1b02dc09..0c4b7cca 100644 --- a/python/Pubnub.py +++ b/python/Pubnub.py @@ -152,36 +152,36 @@ def receive(message) : ## Capture User Input channel = args['channel'] callback = args['callback'] - timetoken = 'timetoken' in args and args['timetoken'] or 0 - ## Begin Recusive Subscribe - try : - ## Wait for Message - response = self._request([ - 'subscribe', - self.subscribe_key, - channel, - '0', - str(timetoken) - ]) - - messages = response[0] - args['timetoken'] = response[1] - - ## If it was a timeout - if not len(messages) : - return self.subscribe(args) - - ## Run user Callback and Reconnect if user permits. - for message in messages : - if not callback(message) : - return - - ## Keep Listening. - return self.subscribe(args) - except Exception: - time.sleep(1) - return self.subscribe(args) + ## Begin Subscribe + while True : + + timetoken = 'timetoken' in args and args['timetoken'] or 0 + + try : + ## Wait for Message + response = self._request([ + 'subscribe', + self.subscribe_key, + channel, + '0', + str(timetoken) + ]) + + messages = response[0] + args['timetoken'] = response[1] + + ## If it was a timeout + if not len(messages) : + continue + + ## Run user Callback and Reconnect if user permits. + for message in messages : + if not callback(message) : + return + + except Exception: + time.sleep(1) return True