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

ResourceWarning when open() fails with io.UnsupportedOperation: File or stream is not seekable #65509

Closed
vadmium opened this issue Apr 19, 2014 · 6 comments
Assignees
Labels
topic-IO type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented Apr 19, 2014

BPO 21310
Nosy @pitrou, @vstinner, @vadmium, @serhiy-storchaka
Files
  • io_open_resource_warning.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2014-06-09.17:42:46.103>
    created_at = <Date 2014-04-19.03:23:49.471>
    labels = ['type-bug', 'expert-IO']
    title = 'ResourceWarning when open() fails with io.UnsupportedOperation: File or stream is not seekable'
    updated_at = <Date 2014-06-11.04:20:06.396>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2014-06-11.04:20:06.396>
    actor = 'python-dev'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2014-06-09.17:42:46.103>
    closer = 'serhiy.storchaka'
    components = ['IO']
    creation = <Date 2014-04-19.03:23:49.471>
    creator = 'martin.panter'
    dependencies = []
    files = ['35403']
    hgrepos = []
    issue_num = 21310
    keywords = ['patch']
    message_count = 6.0
    messages = ['216838', '219153', '219361', '220087', '220104', '220233']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'vstinner', 'python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue21310'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    @vadmium
    Copy link
    Member Author

    vadmium commented Apr 19, 2014

    >>> f = open("/dev/stdout", "w+b")  # Or any non-seekable file, pipe, etc
    __main__:1: ResourceWarning: unclosed file <_io.FileIO name='/dev/stdout' mode='rb+'>
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    io.UnsupportedOperation: File or stream is not seekable.

    It is mainly just the annoyance of the ResourceWarning, so nothing major. I think this was previously identified in bpo-18116, but it looks like that bug was side-stepped by removing an equivalent fdopen() call.

    No ResourceWarning happens with an unbuffered file. I haven’t looked at the code but I guess the UnsupportedOperation might only be raised after trying to wrap the open FileIO object in a BufferedWriter object.

    @ezio-melotti ezio-melotti added the type-bug An unexpected behavior, bug, or error label May 26, 2014
    @serhiy-storchaka
    Copy link
    Member

    See also bpo-20074.

    @serhiy-storchaka
    Copy link
    Member

    Here is a patch which fixes warnings.

    @serhiy-storchaka serhiy-storchaka self-assigned this May 29, 2014
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 9, 2014

    New changeset 1e30ecbfe181 by Serhiy Storchaka in branch '2.7':
    Issue bpo-21310: Fixed possible resource leak in failed open().
    http://hg.python.org/cpython/rev/1e30ecbfe181

    New changeset 17e7934905ab by Serhiy Storchaka in branch '3.4':
    Issue bpo-21310: Fixed possible resource leak in failed open().
    http://hg.python.org/cpython/rev/17e7934905ab

    New changeset 9c724c428e1f by Serhiy Storchaka in branch 'default':
    Issue bpo-21310: Fixed possible resource leak in failed open().
    http://hg.python.org/cpython/rev/9c724c428e1f

    @serhiy-storchaka
    Copy link
    Member

    Thanks Victor for the review. Thanks Martin for the report.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 11, 2014

    New changeset a98fd4eeed40 by Serhiy Storchaka in branch '3.4':
    PyErr_NormalizeException doesn't like being called with an exception set
    http://hg.python.org/cpython/rev/a98fd4eeed40

    New changeset 55c50c570098 by Serhiy Storchaka in branch 'default':
    PyErr_NormalizeException doesn't like being called with an exception set
    http://hg.python.org/cpython/rev/55c50c570098

    @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
    topic-IO type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants