On Thu, Apr 8, 2010 at 04:32, Bert Huijben <bert_at_qqmail.nl> wrote:
>> +def patch_no_index_line(sbox):
>> + "patch with no index lines"
>> + sbox.build()
>> + wc_dir = sbox.wc_dir
>> + patch_file_path =
> This line reintroduces the issue I fixed in the other tests in r930990.
> Stefan: Answering your question: It seems the handle must be closed before leaving the function. (I don't mind where, as long as it fixes the errors)
> Greg: You just fixed several other functions to use open(...).read(), without closing the handle. This doesn't cause the same error, so this file is somehow closed without the explicit close required above. Do you have any idea why mkstemp() does need the explicit close? (Python bug?)
I see you removed the mkstemp() today, but let me explain anyways...
Python uses explicit reference counting on its objects, and will
destroy them when no references exist. The file object will close its
handle at destruction time. Thus, in a statement like:
contents = open(file).read()
The file handle returned by open() exists during the evaluation of the
expression. First, it is held by the internals as the result of
open(). Then the "read" method is looked up on it, and a "bound
method" object is the result. That object holds a reference to the
file object. Then the bound method is called, returning the contents.
The bound method then has its reference count decremented, hitting
zero, so it gets destroyed. Which decref's the file object, which gets
destroyed, which closes the file handle.
In the mkstemp case, you're returned a file descriptor -- a simple
integer. Integers don't have file-closing behavior associated with
ps. technically, some Python implementations (eg IronPython or Jython)
do not refcount, but that has no bearing on our test suite
Received on 2010-04-12 15:09:58 CEST