[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Break out of program in interpreter
- From: Thijs Schreijer <thijs@...>
- Date: Tue, 14 May 2013 15:20:34 +0000
> -----Original Message-----
> From: firstname.lastname@example.org [mailto:email@example.com] On
> Behalf Of Jose Torre-Bueno
> Sent: dinsdag 14 mei 2013 16:36
> To: Lua mailing list
> Subject: Re: Break out of program in interpreter
> > while true do os.execute('echo hello world') end
> > cannot be stopped with ^C.
> Thanks everybody you explained the question. Now a somewhat related
> Is there any way to pause a lua program for less than one second?
> Thanks to your help I can write a loop like this:
> while true do
> condition_met = some_function_that_should_no_be_done_too_often()
> if condition_met or not os.execute('sleep 1') then break end
> Which will end the loop if either the condition is met or the user gets
> bored and hits ^C
> Obviously if the other function were lua I could use coroutines but if the
> other function is a separate program I am calling with os.execute and it
> uses significant system resources to do its checking I need some way to
> wait a reasonable time before calling it again.
> Is there any way to make this time less than one second?
For a quick and dirty fix to this I have a script that uses LuaSocket. Creates a fake socket, and then listens on that socket with a timeout of x seconds. If set to 0.1 second timeout, it will block for that period.
In another (slightly more complex) one I used Copas and CopasTimer. Create a fake socket, let copas listen on that, and use CopasTimer to create timers to be executed at any interval.