[New-bugs-announce] [issue4604] close() seems to have limited effect

Skip Montanaro report at bugs.python.org
Tue Dec 9 01:11:21 CET 2008


New submission from Skip Montanaro <skip at pobox.com>:

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.

----------
components: Interpreter Core
messages: 77376
nosy: skip.montanaro
severity: normal
status: open
title: close() seems to have limited effect
type: behavior
versions: Python 3.0

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4604>
_______________________________________


More information about the New-bugs-announce mailing list