[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [5.1.4/newbie] How to check end script?
- From: Daniel Silverstone <dsilvers@...>
- Date: Mon, 7 Mar 2011 16:48:32 +0000
On Mon, Mar 07, 2011 at 05:32:28PM +0100, Axel Kittenberger wrote:
> > Both do the job, but os.exit() will cause the process to end immediately
> > without the garbage collector doing a final clean up. I found this out the
> > hard way when I had some code that would flush a file and close it when the
> > object was garbage collected, but calling os.exit() would leave the file in
> > an inconsistent state. Doing a 'return' from the script would cause the GC
> > to kick in.
> I suppose you had some extra on "__gc"? I always believed the Linux
> kernel will call a clean close() on all open file descriptors when
> terminating a process.
Assuming these are file descriptors created with io.open or io.popen then they
have C-library FILE* objects backing them. These can hold writes in memory
until they need to be flushed, are flushed explicitly, or are closed with
fclose(). No amount of kernel-based cleanup will help with that :-)
Daniel Silverstone http://www.digital-scurf.org/
PGP mail accepted and encouraged. Key Id: 3CCE BABE 206C 3B69