pyserial and threads

Chris Angelico rosuav at gmail.com
Thu Sep 17 11:42:08 CEST 2015


On Thu, Sep 17, 2015 at 7:28 PM, pozz <pozzugno at gmail.com> wrote:
> At startup I open the ports and create and start a thread to manage the
> receiving. When a byte is received, I call the .write() method for all the
> other ports.
>
> It works, but sometimes it seems to block. I think I haven't used correctly
> the threads.
>

Seems a fairly reasonable model. From what I'm seeing here, you start
a thread to read from each serial port, but then those threads will
make blocking writes to all the other serial ports. Is it possible
that one of them is getting full?

When I do this kind of thing with TCP/IP sockets, I usually end up
having to go non-blocking in both directions, and maintaining a buffer
of unsent text for each socket. You may find that you need to do the
same thing here.

Where's the code getting blocked?

ChrisA


More information about the Python-list mailing list