Author r.david.murray
Recipients alexis.d, brian.curtin, neologix, r.david.murray
Date 2012-03-28.19:28:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1332962884.58.0.842885717881.issue14433@psf.upfronthosting.co.za>
In-reply-to
Content
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@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@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.
History
Date User Action Args
2012-03-28 19:28:04r.david.murraysetrecipients: + r.david.murray, brian.curtin, neologix, alexis.d
2012-03-28 19:28:04r.david.murraysetmessageid: <1332962884.58.0.842885717881.issue14433@psf.upfronthosting.co.za>
2012-03-28 19:28:03r.david.murraylinkissue14433 messages
2012-03-28 19:28:03r.david.murraycreate