eryksun added the comment:

In Python 2, the closer for sys.stdout is _check_and_flush, which flushes the 
stream without closing the underlying FILE.

https://hg.python.org/cpython/file/ee879c0ffa11/Python/sysmodule.c#l1377

In Python 3, io.FileIO won't close the underlying file descriptor if closefd is 
False.

    >>> sys.stdout.buffer.raw.closefd
    False

It isn't a writable attribute. It gets initialized to False by create_stdio 
(line 1034).

https://hg.python.org/cpython/file/ab2c023a9432/Python/pythonrun.c#l1006

You'll can call os.close.

Python 2:

    >>> sys.stdout.close(); os.close(1); sys.stdout = open('CONOUT$', 'w', 
buffering=0)
    >>> sys.stdout.fileno()
    1

Python 3:

    >>> sys.stdout.close(); os.close(1); sys.stdout = open('CONOUT$', 'w') 
    >>> sys.stdout.fileno()
    1

----------
components:  -Windows
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22673>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to