New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
close() seems to have limited effect #48854
Comments
Seems like file.close() in 3.0 isn't much of a barrier to further reading: % python3.0
Python 3.0rc3+ (py3k:67338M, Nov 22 2008, 06:47:23)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> fp = open("/etc/services")
>>> ct = fp.read(1048)
>>> print (ct[-80:], end='') ; fp.close() ; ct = fp.read(17) ; print (ct)
compressnet 2/udp # Management Utility
compressnet 2/tcp # Management Utility The second read() should raise an exception. Same code, 2.6: % python2.6
Python 2.6+ (release26-maint:66821:66833, Oct 30 2008, 22:16:1)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> fp = open("/etc/services")
>>> ct = fp.read(1048)
>>> print (ct[-80:], end='') ; fp.close() ; ct = fp.read(17) ; print (ct)
compressnet 2/udp # Management Utility
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file
compressnet 2/tcp # M>>> Culled this from a posting to comp.lang.python. |
Indeed, it seems to happen if you first call read() before calling close(). |
Here's a test case (diff against Lib/test/test_io.py). This fails for |
fixed patch. I'm still a bit clumsy with the assertRaises stuff. |
Here's a minimal patch to BufferedReader.read() which causes the test |
|
Amaury> - It should use I think some other places will need this change then. Note that I don't know the io code at all. I was just trying to provide a Skip |
Attached more generic version of the patch. |
Expanded the test a bit and committed the patch in r68454. Thanks! |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: