On Wed, 26 Apr 2006 17:29:50 +0100, Nicos Gollan <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> is it intentional that XML::Document.file doesn't seem to close files?
>
> With mod_ruby, I'm getting a lot of open files from calls to that
> method, and
> I haven't found a way to close those files again.
>
The behaviour I'm observing here is that the XML::Parser keeps files open
until it's garbage collected. Since XML::Document.file uses a parser
behind the scenes, this is holding the file open:
x = XML::Document.file
'/home/rosco/workspace/libxml/tests/model/rubynet.xml'
# => <?xml version="1.0"?> ...
puts `/usr/sbin/lsof /home/rosco/workspace/libxml/tests/model/rubynet.xml`
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
irb 25366 rosco 3r REG 253,2 3021 10997895
/home/rosco/workspace/libxml/tests/model/rubynet.xml
# => nil
GC.start
# => nil
puts `/usr/sbin/lsof /home/rosco/workspace/libxml/tests/model/rubynet.xml`
# => nil
> In theory, it should not be necessary to keep a file open after the
> parser is
> done with it, right?
>
I'd tend to agree, though at this point I'm not sure whether it's
something we can fix (obviously I'll look into it :)).
For now, here's a workaround you might try:
doc =
File.open('/home/rosco/workspace/libxml/tests/model/rubynet.xml','r') do
|f|
XML::Parser.io(f).parse
end
# => <?xml version="1.0"?> ...
puts `/usr/sbin/lsof /home/rosco/workspace/libxml/tests/model/rubynet.xml`
# => nil
Hope that helps,
--
Ross Bamford - [EMAIL PROTECTED]
_______________________________________________
libxml-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/libxml-devel