summaryrefslogtreecommitdiffstats
path: root/Lib/io.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/io.py')
-rw-r--r--Lib/io.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 54de504..1458b47 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -1199,6 +1199,10 @@ class BufferedRandom(BufferedWriter, BufferedReader):
self.flush()
# First do the raw seek, then empty the read buffer, so that
# if the raw seek fails, we don't lose buffered data forever.
+ if self._read_buf and whence == 1:
+ # Undo read ahead.
+ with self._read_lock:
+ self.raw.seek(self._read_pos - len(self._read_buf), 1)
pos = self.raw.seek(pos, whence)
with self._read_lock:
self._reset_read_buf()