How to prevent multiple send in ThreadedClient

26 views
Skip to first unread message

Akmal Hakimi

unread,
Jul 11, 2017, 6:19:47 AM7/11/17
to ws4py
Hi. I am currently developing a python program that's using ws4py to stream audio to Watson Speech to Text. I stumbled into a problem where sometime a data is sent when the previous data is still sending. This returns the error message "ssl routines:ssl3_write_pending:bad write retry". Here's snippet of my code:

def stream_dummy_audio(self):
        while not self.listening:
            time.sleep(0.1)

        reccmd = ["arecord", "-f", "S16_LE", "-r", "16000", "-t", "raw"]
        p = subprocess.Popen(reccmd, shell=False ,stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        while self.listening:
            data = p.stdout.read(1024)

            try: self.send(bytearray(data), binary=True)
            except ssl.SSLError: pass
            except Exception, e : 
                print "debug: Error in connection. Keep alive thread stopped"
                self.closed(0,"Connection error")    

Is there any way to make the self.send(bytearray(data), binary=True) line only executed if the previous send already finished?

Sylvain Hellegouarch

unread,
Jul 12, 2017, 4:30:26 AM7/12/17
to ws...@googlegroups.com
Hi Akmal,

Ah... TLS and ws4py, it could be improved indeed.

I see you catch SSLError, do you get a specific one by any chance? If so, could you paste it please?

Thanks,
- Sylvain

--
You received this message because you are subscribed to the Google Groups "ws4py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ws4py+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Akmal Hakimi

unread,
Jul 13, 2017, 12:15:37 AM7/13/17
to ws4py
Hi Sylvain

Not exactly what was catched but this is the full error message that I get:

Exception in thread WebSocketClient:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/sarif/.local/lib/python2.7/site-packages/ws4py/websocket.py", line 524, in run
    if not self.once():
  File "/home/sarif/.local/lib/python2.7/site-packages/ws4py/websocket.py", line 406, in once
    if not self.process(self.buf):
  File "/home/sarif/.local/lib/python2.7/site-packages/ws4py/websocket.py", line 484, in process
    self._write(s.pong(ping.data))
  File "/home/sarif/.local/lib/python2.7/site-packages/ws4py/websocket.py", line 285, in _write
    self.sock.sendall(b)
  File "/usr/lib/python2.7/ssl.py", line 229, in sendall
    v = self.send(data[count:])
  File "/usr/lib/python2.7/ssl.py", line 198, in send
    v = self._sslobj.write(data)
SSLError: [Errno 1] _ssl.c:1296: error:1409F07F:SSL routines:SSL3_WRITE_PENDING:bad write retry
To unsubscribe from this group and stop receiving emails from it, send an email to ws4py+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Sylvain Hellegouarch

unread,
Jul 14, 2017, 4:21:55 AM7/14/17
to ws...@googlegroups.com
Hi Akmal,

Yeah, that's unfortunately what I expected :/

Please have a look at https://github.com/Lawouach/WebSocket-for-Python/issues/174 see if that helps.

- Sylvain

To unsubscribe from this group and stop receiving emails from it, send an email to ws4py+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Akmal Hakimi

unread,
Jul 18, 2017, 11:02:52 PM7/18/17
to ws...@googlegroups.com
Hi Sylvain. 

--
You received this message because you are subscribed to a topic in the Google Groups "ws4py" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ws4py/EdH2vK4d3IY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ws4py+unsubscribe@googlegroups.com.

Akmal Hakimi

unread,
Jul 18, 2017, 11:04:44 PM7/18/17
to ws...@googlegroups.com
Hi Sylvain

I tried the solution suggested by dalai4git and it gives me this error instead:

Exception in thread WebSocketClient:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 504, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/sarif/.local/lib/python2.7/site-packages/ws4py/websocket.py", line 541, in run
    if not self.once():
  File "/home/sarif/.local/lib/python2.7/site-packages/ws4py/websocket.py", line 423, in once
    if not self.process(self.buf):
  File "/home/sarif/.local/lib/python2.7/site-packages/ws4py/websocket.py", line 501, in process
    self._write(s.pong(ping.data))
  File "/home/sarif/.local/lib/python2.7/site-packages/ws4py/websocket.py", line 297, in _write
    except WantWriteError:
NameError: global name 'WantWriteError' is not defined

Reply all
Reply to author
Forward
0 new messages