server.websocket_safe_read will never return multiple messages
- [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
- [x] I've read and agree to the Code of Conduct.
- [x] I've searched for any related issues and avoided creating a duplicate issue.
Description
The documentation http://python-slackclient.readthedocs.io/en/latest/source/classes.html#slackclient._server.Server.websocket_safe_read suggests that server.websocket_safe_read can return several messages separated by newline. Current implementation of server.websocket_safe_read will never return multiple messages because it returns after the first loop. This would also cause client.rtm_read() to returns at max one message.
Reproducible in:
- [ ] This is reproducible in the sample project. python-slackclient version: 1.0.1 Python Version: 2.7.3 OS Version: Ubuntu 12.04.5
Steps to reproduce:
from slackclient import SlackClient
sc = SlackClient(<token>)
sc.rtm_connect()
- Trigger activities that would stream several messages (e.g: send multiple personal messages to the bot)
sc.server.websocket_safe_read()
Expected result:
returns list of multiple messages in one call
Actual result:
returns one message after the first call to self.websocket.recv()
Attachments:
I was using the sample, which polled once per second. It didn't work out because our system has more than one event coming in every second. I made these changes in my version of websocket_safe_read, and it works so far.
while True:
try:
data += "{0}\n".format(self.websocket.recv())
except SSLError as e:
if e.errno == 2:
break
raise
return data.rstrip()
Hi @nisrinaluthf! We'll be redesigning the way that RTM is implemented in version 2 which will improve the way events are emitted.
Work is still underway around the redesign; see #384 for more details. With respect to the issue originally reported. I've not been able to reproduce this issue. I'm closing this issue, but should it occur again feel free to reopen it.