Menu

#185 SocketSerial.read() never returns data when timeout==0

v2.7
closed-fixed
None
5
2015-08-05
2015-06-28
No

Situation
I create a SerialSocket with timeout set to 0 and the try to read bytes from this socket when they become available:

import serial
socketserial = serial.serial_for_url('socket://localhost:5000', timeout=0)
while True:
    print socketserial.read(1)

Observed behaviour
read(1) always returns an empty string, regardless of data available at the socket.

Expected behaviour
I would have expected it to return a character at a time when data becomes available at the socket.

Potential solution
I believe this may be avoided by modifying the read loop of SerialSocket.read() at protocol_socket.py, line 151 onward:

while len(data) < size and (timeout is None or time.time() < timeout):
    try:
        ...

to read:

while len(data) < size:
    try:
        ...
    if not (timeout is None or time.time() < timeout):
        break

so that at least one read is always attempted.

Thanks!
Rob

Related

Bugs: #186

Discussion

  • Chris Liechti

    Chris Liechti - 2015-08-05
    • status: open --> closed-fixed
    • assigned_to: Chris Liechti
     
  • Chris Liechti

    Chris Liechti - 2015-08-05
     

Log in to post a comment.