[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: (not) handling new programming idioms with grace
- From: Hisham <h@...>
- Date: Fri, 20 Jul 2018 19:06:57 -0300
On 18 July 2018 at 15:55, Roberto Ierusalimschy <roberto@inf.puc-rio.br> wrote:
>> A few months ago I wrote some code to recursively dive into directories,
>> using something like:
>>
>> [...]
>>
>> I was exhausting file descriptors before my program finished [1]. Upon
>> investigation, it was because iterating over a directory uses a file
>> descriptor, and because GC had yet to kick in, I had a bazillion open
>> directories. I had to change the iterator to close and release the
>> directory upon finishing instead of relying upon the GC. And this is in
>> what I consider library code.
>
> I think a few rules could greatly improve things. Unfortunately, I was
> not following them :-)
>
> - As Tomas pointed out, iterators should release their resources as soon
> as they reach the last element. Sadly, my implementation of a directory
> iterator in PiL does not do that; but the implementation of io.lines in
> the standard library does :-)
The implementation of lfs.dir in LuaFileSystem does close the
directory handle as it reaches the last element. Unfortunately, that's
not good enough, because of course, when given a "for" iterator, users
can (and do) use "break".
-- Hisham
- References:
- (not) handling new programming idioms with grace, John Belmonte
- Re: (not) handling new programming idioms with grace, Dibyendu Majumdar
- Re: (not) handling new programming idioms with grace, Roberto Ierusalimschy
- Re: (not) handling new programming idioms with grace, John Belmonte
- Re: (not) handling new programming idioms with grace, Viacheslav Usov
- Re: (not) handling new programming idioms with grace, John Belmonte
- Re: (not) handling new programming idioms with grace, Roberto Ierusalimschy
- Re: (not) handling new programming idioms with grace, Gé Weijers
- Re: (not) handling new programming idioms with grace, Andrew Starks
- Re: (not) handling new programming idioms with grace, Sean Conner
- Re: (not) handling new programming idioms with grace, Roberto Ierusalimschy