python-slack-sdk icon indicating copy to clipboard operation
python-slack-sdk copied to clipboard

server.websocket_safe_read will never return multiple messages

Open nisrinaluthf opened this issue 10 years ago • 3 comments

  • [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()
  1. Trigger activities that would stream several messages (e.g: send multiple personal messages to the bot)
  2. 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:

nisrinaluthf avatar Aug 05 '16 17:08 nisrinaluthf

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()

bradtiffany avatar Dec 13 '16 22:12 bradtiffany

Hi @nisrinaluthf! We'll be redesigning the way that RTM is implemented in version 2 which will improve the way events are emitted.

RodneyU215 avatar Oct 04 '18 23:10 RodneyU215

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.

RodneyU215 avatar Apr 02 '19 05:04 RodneyU215