Skip to content
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

Closed
smontanaro opened this issue Dec 9, 2008 · 9 comments
Closed

close() seems to have limited effect #48854

smontanaro opened this issue Dec 9, 2008 · 9 comments
Labels
extension-modules C modules in the Modules dir release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@smontanaro
Copy link
Contributor

BPO 4604
Nosy @smontanaro, @amauryfa, @pitrou, @tiran
Files
  • iobug.diff
  • io.patch
  • io_fixes.patch: io module fixes with test
  • 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:

    assignee = None
    closed_at = <Date 2009-01-09.20:08:25.385>
    created_at = <Date 2008-12-09.00:11:20.450>
    labels = ['extension-modules', 'type-bug', 'library', 'release-blocker']
    title = 'close() seems to have limited effect'
    updated_at = <Date 2009-01-09.20:08:25.384>
    user = 'https://github.com/smontanaro'

    bugs.python.org fields:

    activity = <Date 2009-01-09.20:08:25.384>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2009-01-09.20:08:25.385>
    closer = 'pitrou'
    components = ['Extension Modules', 'Library (Lib)']
    creation = <Date 2008-12-09.00:11:20.450>
    creator = 'skip.montanaro'
    dependencies = []
    files = ['12306', '12309', '12450']
    hgrepos = []
    issue_num = 4604
    keywords = ['patch']
    message_count = 9.0
    messages = ['77376', '77440', '77446', '77450', '77455', '77475', '77476', '78295', '79498']
    nosy_count = 5.0
    nosy_names = ['skip.montanaro', 'hdima', 'amaury.forgeotdarc', 'pitrou', 'christian.heimes']
    pr_nums = []
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue4604'
    versions = ['Python 3.0']

    @smontanaro
    Copy link
    Contributor Author

    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.

    @smontanaro smontanaro added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Dec 9, 2008
    @tiran tiran added extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir release-blocker and removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Dec 9, 2008
    @pitrou
    Copy link
    Member

    pitrou commented Dec 9, 2008

    Indeed, it seems to happen if you first call read() before calling close().

    @smontanaro
    Copy link
    Contributor Author

    Here's a test case (diff against Lib/test/test_io.py). This fails for
    me on OS X 10.5.5 with the tip of the py3k branch.

    @smontanaro
    Copy link
    Contributor Author

    fixed patch. I'm still a bit clumsy with the assertRaises stuff.

    @smontanaro
    Copy link
    Contributor Author

    Here's a minimal patch to BufferedReader.read() which causes the test
    to pass. I will leave it for smarter people to decided whether or not
    all the other read() methods need the same test.

    @amauryfa
    Copy link
    Member

    • The patch corrects a specific case, but not others: for example if the
      file is opened in "r" (text) mode.
      There are also other methods to test: peek(), read1()...

    • It should use
      self._checkClosed()
      which already raises the same exception with the same message.

    @smontanaro
    Copy link
    Contributor Author

    Amaury> - It should use
    Amaury> self._checkClosed()
    Amaury> which already raises the same exception with the same message.

    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
    simple test case and a simple fix. Feel free to generalize it as necessary.

    Skip

    @loewis loewis mannequin added deferred-blocker and removed release-blocker labels Dec 10, 2008
    @loewis loewis mannequin added release-blocker and removed deferred-blocker labels Dec 20, 2008
    @hdima
    Copy link
    Mannequin

    hdima mannequin commented Dec 26, 2008

    Attached more generic version of the patch.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 9, 2009

    Expanded the test a bit and committed the patch in r68454. Thanks!

    @pitrou pitrou closed this as completed Jan 9, 2009
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir release-blocker stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants