classification
Title: file,close() can fail assert on Windows in 2.7
Type: crash Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, amaury.forgeotdarc, sbt
Priority: normal Keywords:

Created on 2012-09-10 14:16 by sbt, last changed 2020-04-16 20:29 by benjamin.peterson. This issue is now closed.

Messages (4)
msg170188 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-09-10 14:16
With Python 2.7 on Windows the following crashes with an assertion:

    >>> import os
    [43042 refs]
    >>> f = open("foobar", "wb")
    [43048 refs]
    >>> os.close(f.fileno())
    [43048 refs]
    >>> f.close()
    <Failed assertion>

A box pops up with

    Program: C:\Repos\cpython-27\PCbuild\python_d.exe
    File: f:\dd\vctools\crt_bld\self_x86\crt\src\close.c
    Line: 48

    Expression: (_osfile(fh) & FOPEN)

Python 3.2 and 3.3 give IOError(EBADF, ...) as expected.

Compare #15261 and #15263.
msg170192 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-09-10 14:44
Is it also the case for other file operations?  Here is a list that may use a closed FILE object:
    f.write('something')
    f.read(1)
    print >>f, 'something'
    f.seek(0)
    f.tell()
    f.truncate(0)
    f.flush()
    f.isatty()
    f.readlines()
    f.writelines(['x'])
    list(f)
msg170195 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2012-09-10 14:57
If buffering is off then they all fail the assertion except isatty().
msg366616 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2020-04-16 18:05
Python 2 is EOL.
History
Date User Action Args
2020-04-16 20:29:14benjamin.petersonsetstatus: open -> closed
resolution: wont fix
stage: needs patch -> resolved
2020-04-16 18:05:30ZackerySpytzsetnosy: + ZackerySpytz
messages: + msg366616
2012-09-10 14:57:23sbtsetmessages: + msg170195
2012-09-10 14:44:07amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg170192
2012-09-10 14:16:38sbtcreate