You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
io.BufferedRWPair doc warning may need clarification #82776
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2019-10-26.05:19:33.715>labels= ['type-bug', '3.7', 'docs']
title='io.BufferedRWPair doc warning may need clarification'updated_at=<Date2019-10-26.05:30:22.117>user='https://bugs.python.org/rgov'
The documentation for the io.BufferedRWPair class gives this 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 have a hard time understanding what this warning is trying to tell me.
What does it mean to "synchronize accesses"?
Why can't I pass the same object as reader and writer? The docstring in _pyio.py says, "This is typically used with a socket or two-way pipe."
How does BufferedRandom, which adds the seek() and tell() interfaces, address the issue of "synchroniz[ing] accesses"? Is synchronization automatic? What does this do for sockets or pipes which cannot seek?
I'm not sure if it applies to sockets, pipes, etc. though.
The pySerial documentation advises using io.BufferedRWPair(x, x) where x is a serial device. But this StackOverflow post reports that it is problematic, in line with the warning. (The author appears to be talking about Windows.)
Activity
rgov commentedon Oct 26, 2019
The documentation for the io.BufferedRWPair class gives this warning:
I have a hard time understanding what this warning is trying to tell me.
What does it mean to "synchronize accesses"?
Why can't I pass the same object as reader and writer? The docstring in _pyio.py says, "This is typically used with a socket or two-way pipe."
How does BufferedRandom, which adds the seek() and tell() interfaces, address the issue of "synchroniz[ing] accesses"? Is synchronization automatic? What does this do for sockets or pipes which cannot seek?
rgov commentedon Oct 26, 2019
The origin of this warning involves interleaving read and write operations, and was added here: https://bugs.python.org/issue12213
I'm not sure if it applies to sockets, pipes, etc. though.
The pySerial documentation advises using io.BufferedRWPair(x, x) where x is a serial device. But this StackOverflow post reports that it is problematic, in line with the warning. (The author appears to be talking about Windows.)
https://stackoverflow.com/questions/24498048/python-io-modules-textiowrapper-or-buffererwpair-functions-are-not-playing-nice
cmaloney commentedon Nov 19, 2026
Socket uses this same pattern. Should make it as safe as possible in the current code and should remove the warning.