Message397907
3c22fb7d6b37">reecepeg@3c22fb7d6b37 Pulpmill % python3 --version
Python 3.9.1
When buffering a small file, calling peek() can read in the entire underlying thing and close it, so then following with a read() throws an error about the file being closed already even though peek should not have that effect.
Reproducible Steps:
>>> r = BufferedReader(requests.get("https://google.com", stream=True).raw)
>>> r.peek(2)[:2]
b'\x1f\x8b'
>>> r.peek()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: peek of closed file
>>> r.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: read of closed file
However, in the case of a larger stream it appears to work since the underlying stream isn't closed yet:
>>> r = BufferedReader(requests.get("https://amazon.com", stream=True).raw)
>>> r.peek(2)[:2]
b'\x1f\x8b'
>>> r.peek(2)[:2]
b'\x1f\x8b'
This seems inconsistent at best. Best I can tell, the issue is here and needs to take the current buffer offset into account.
https://github.com/python/cpython/blob/main/Modules/_io/bufferedio.c#L845 |
|
Date |
User |
Action |
Args |
2021-07-20 20:42:34 | liquidpele | set | recipients:
+ liquidpele |
2021-07-20 20:42:34 | liquidpele | set | messageid: <1626813754.71.0.447249212898.issue44687@roundup.psfhosted.org> |
2021-07-20 20:42:34 | liquidpele | link | issue44687 messages |
2021-07-20 20:42:34 | liquidpele | create | |
|