[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [5.1.4/newbie] How to check end script?
- From: Sean Conner <sean@...>
- Date: Mon, 7 Mar 2011 10:38:40 -0500
It was thus said that the Great Steve Litt once stated:
> On Monday 07 March 2011 05:02:16 Shmuel Zeigerman wrote:
> > On 07/03/2011 11:40, Gilles Ganault wrote:
> > > I need to exit a script in case the user forgot to pass a parameter,
> > > and noticed that return works in the "if" block but doesn't when used
> > > in the main loop: [snip]
> > Instead of just `return', you can always say:
> > do return end
> > and that will return from the script.
> I didn't know that. I've always just used os.exit().
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.
-spc (just an FYI ... )