Maybe we could catch OOM and out-of-fd errors and run gc() before throwing
an error to the user?

On Tuesday, October 7, 2014, Keno Fischer <[email protected]>
wrote:

> Yes, it's definitely supposed to be closed by the garbage collector.
> Eachline only closes it manually if it opened it, which it didn't in
> this case. Maybe better would be
>
> open("testfile","r") do f
>    collect(eachline(f))
> end
>
> On Tue, Oct 7, 2014 at 1:27 PM, ggggg <[email protected] <javascript:;>>
> wrote:
> > I tracked it down under ubuntu with the following commands
> > pdiof julia
> > lsof -p #fromprevoiucommand
> > which lists not only the number of files open, but also the path to the
> > files.  Very useful.
> >
> > I tracked this down and was a bit surprised.  My code was essentially
> doing
> > the following
> > julia> f() = collect(eachline(open("testfile","r")))
> > f (generic function with 1 method)
> > julia> for j=1:typemax(Int)
> >        println(j)
> >        f()
> >        end
> > ...
> > 1011
> > ERROR: opening file testfile: Too many open files
> >  in open at ./iostream.jl:117
> >  in open at ./iostream.jl:125
> >  in anonymous at no file:3
> >
> > which doesn't explicitly close the file I open.  I guess I had assumed
> > eachline would close the file after iteration was finished, though the
> > documentation does not say that it will.  I had further thought that the
> > garbage collector would close the file once the function was done
> executing,
> > which apparently also doesn't happen. I must have gotten the impression
> from
> > python that the file would be automatically closed (sometime) after the
> > function was done, since roughly equivalent code in python does not
> crash.
> > Is the garbage collector supposed to close the file in this case?
> >
> >
>

Reply via email to