TypeError when unplugging serial USB port while reading
Brought to you by:
cliechti
I'm using pyserial to communicate with an FTDI USB-to-serial converter on Linux (Debian 6, 32). When unplugging the device while reading, pyserial sometimes throws a TypeError:
Python 2.7.3
pyserial: 2.6
Traceback (most recent call last):
File "[hidden]", line XX, in run
byte = self.pyserialHandler.read(1)
File "[...]/site-packages/serial/serialposix.py", line 453, in read
buf = os.read(self.fd, size-len(read))
TypeError: an integer is required
Instead of raising a TypeError, it should fail with a SerialException.
Correct title
Unclear what is happening here. Are you sure your example isn't using threads and the other one closes the port after it detects an error? This could explain that self.fd becomes None and thus triggers such an exception as you describe.
Could not reproduce in my tests with pySerial 2.7. Always getting a SerialException.