Closed takluyver closed 8 years ago
Good work with io.BufferedRWPair
, Tested OK with pexpect on linux/mac/freebsd, no failures.
Because of the buffering, if someone reads through the object interface, and then uses the FD directly
I think we can safely assume exclusive read rights in PtyProcess. I'll leave it up to you to version bump and release at your discretion.
This is experimental - it passes ptyprocess' own tests, but we should test it more extensively before we decide to merge it.
We can't just open the r/w file object with buffering enabled, because that fails with an error on a non-seekable stream. That makes sense for file access - buffering without seeking would break mixed reads and writes. A pty is a bit odd: although we have a single file descriptor, it's conceptually more like two separate streams. Luckily, Python provides BufferedRWPair to join two file objects - one reading and one writing - into a single thing.
Because of the buffering, if someone reads through the object interface, and then uses the FD directly to read further, they may lose data. However, I think that using the FD is still OK so long as you never use the read methods (as Pexpect does). We should check this.
Calls to
PtyProcess.write()
are effectively unbuffered by default, because I call flush() after writing the data. Passingflush=False
will skip this.Closes gh-3