Skip to content

Commit

Permalink
Merge pull request pubnub#49 from nickveys/python-stack-overflow
Browse files Browse the repository at this point in the history
Python library stack overflow
  • Loading branch information
stephenlb committed Nov 10, 2011
2 parents c5b872a + b7f85d3 commit a232fff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
58 changes: 29 additions & 29 deletions python/Pubnub.py
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion python/README
Expand Up @@ -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)

Expand Down

0 comments on commit a232fff

Please sign in to comment.