eryksun added the comment:

Reassigning "f" closes the first file object, but not before the second file 
object gets created. You can write to the already-closed file, assuming the 
write is small enough to not flush the FILE stream buffer (e.g. "beer", given 
an empty 4 KiB buffer). However, closing an already-closed file is an EBADF 
(bad file descriptor) error. In this case, Microsoft's C runtime defaults to 
calling an invalid parameter handler that terminates the process.

File operations have to be guarded to work around this, which isn't implemented 
for 2.x file objects. However, this check is implemented for functions in the 
os module. To avoid killing the process you could check os.fstat(f.fileno()), 
which raises OSError for a bad file descriptor.

----------
nosy: +eryksun

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

Reply via email to