SourceForge has been redesigned. Learn more.

#126 Documentation shows invalid use of io.BufferedRWPair


The documentation here:

says to use BufferedRWPair as follows:

ser = serial.serial_for_url('loop://', timeout=1)
sio = io.TextIOWrapper(io.BufferedRWPair(ser, ser))

However, I had problems with input lines disappearing. The Python documentation for io.BufferedRWPair says, "Warning: BufferedRWPair does not attempt to synchronize accesses to its underlying raw streams. You should not pass it the same object as reader and writer; use BufferedRandom instead."

I found that I could simply use something like sio = io.TextIOWrapper(ser)

I'm not sure what was intended by the example using io.BufferedRWPair. Please confirm and update the documentation.


  • Craig McQueen

    Craig McQueen - 2012-10-11
    • assigned_to: nobody --> cliechti
  • Chris Liechti

    Chris Liechti - 2013-10-16
    • status: open --> pending-works-for-me
    • Group: --> v1.0 (example)
  • Chris Liechti

    Chris Liechti - 2013-10-16

    Without io.BufferedRWPair it fails for me, complaining about the read1() method which is a feature of buffered streams but not of raw io streams (such as Serial). io.BufferedRWPair is required to convert the raw io stream to a buffered one, as io.TextIOWrapper depends on a buffered stream.

    Also io.BufferedRandom does not work as it expects (and tests for) a seekable stream, which Serial is not. I would not worry too much about the note about synchronization. This is certainly a problem when read and write access a file, modifying the common [seek/tell] position. However for the serial port the reading and writing streams are mostly independent from each other (excluding things like software flow control).

  • Chris Liechti

    Chris Liechti - 2013-10-17
    • status: pending-works-for-me --> closed-works-for-me
    • Group: v1.0 (example) --> v2.6

Log in to post a comment.