Package: python3-serial
Version: 2.5-2.1
Severity: normal
Dear Maintainer,
when used in TCP mode ('socket://<address>:<port>'), python3-serial
will loose most of the received characters. This is because
SocketSerial.read() _replaces_ the buffer instead of appending to it:
[...]
data = bytearray()
timeout = time.time() + self._timeout
while len(data) < size and time.time() < timeout:
try:
# an implementation with internal buffer would be better
# performing...
> data = self._socket.recv(size - len(data))
except socket.timeout:
# just need to get out of recv form time to time to check if
# still alive
continue
except socket.error as e:
# connection fails -> terminate loop
raise SerialException('connection failed (%s)' % e)
return bytes(data)
As a workaround, read() can be called with size=1, with the obvious
impact on performance.
There are a couple of additional bugs concerning timeout handling of
SocketSerial.read():
1. The socket timeout is hardcoded to 2 seconds. When setting smaller
values with setTimeout(), read() will still wait for 2 seconds in
most cases (i.e. unless there was data to be read and reading took
longer than the timeout):
>>> f.setTimeout(.1)
>>> start_time=time.time(); f.read(); print(time.time() - start_time)
b''
2.0022289752960205
With some protocols or tasks, 2 seconds can be way too long.
2. Not setting a timeout (the default is blocking mode) will cause
read() to fail:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/serial/socket_connection.py", line
136, in read
timeout = time.time() + self._timeout
TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'
3. Setting timeout to 0 (non-blocking mode) causes read() to never
return any data.
The while loop won't do even a single iteration, so no chance to
read from the socket.
While there has been some module level refactoring, pyserial 2.6 still
ships a SocketSerial class with the above bugs.
-- System Information:
Debian Release: 7.0
APT prefers testing
APT policy: (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 3.7-trunk-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages python3-serial depends on:
ii python3 3.2.3-5
python3-serial recommends no packages.
Versions of packages python3-serial suggests:
pn python3-wxgtk2.8 | python3-wxgtk <none>
-- no debconf information
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]