I assume you are using PySerial on a unix platform ...
Since PySerial objects implement fileno () to get the base file descriptor, you can pass them directly to select , which allows you to work with multiple PySerial objects at the same time.
Another alternative would be to set nonblocking () and deal with the fact that your reads and writes may return errno.EWOULDBLOCK errors. This is probably the easiest way.
A third alternative would be to use twisted serial ports if you don't miss your head around how things are twisted.
Update
For Windows, pretty much your only alternative, besides using streams, is to use the inWaiting () method. Interrogate all your serial ports by regularly inWaiting() . If there are waiting things, you can read this and only that many bytes are non-blocking.
Unfortunately, pyserial does not have “how much free space there is in the output buffer,” which means that when writing to serial ports you run the risk of blocking. If you use a typical serial port protocol, a default buffer size of a few kilobytes will ensure that this is usually not a problem.
source share