[issue14433] Python 3 interpreter crash with memoryview and os.fdopen

R. David Murray report at bugs.python.org
Wed Mar 28 21:28:04 CEST 2012


R. David Murray <rdmurray at bitdance.com> added the comment:

To make this a little clearer, here's an even simpler example:

  >>> import os
  >>> os.fdopen(0)
<_io.TextIOWrapper name=0 mode='r' encoding='UTF-8'>
  >>> 1
__main__:1: ResourceWarning: unclosed file <_io.TextIOWrapper name=0 mode='r' encoding='UTF-8'>
  1
  >>>
  rdmurray at hey:~/python/p32>

What is happening here is that the file returned by os.fdopen is assigned to _, and then when I enter '1' *it* gets assigned to _, and the file gets gced and closed.  You can also see this directly:

  >>> import os
  >>> f = os.fdopen(0)
  >>> f.close()
  >>>
  rdmurray at hey:~/python/p32>

I explain this at length because I didn't understand it until I played around with it.

@Brian: this isn't a crash.  It is completely equivalent to pressing <ctl>D at the interactive interpreter prompt.

----------
nosy: +r.david.murray
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14433>
_______________________________________


More information about the Python-bugs-list mailing list