On Mon, Nov 30, 2009 at 5:57 PM, John W. Krahn <[email protected]> wrote:
> David Schmidt wrote:
>>
>> 2009/11/30 Jay Savage <[email protected]>:
>>>
>>> Either way, you should be able to use the built-in functions to
>>> accomplish your task. See the docs for sleep(), alarm(), and select()
>>> for more info.
>>
>> Sorry for the bad explanation of my problem.
>>
>> Yes my program has to continue while waiting for the timeout.
>> You code example doesn't work for me because my program is an entire
>> Catalyst application which I dont think is a good idea to put into an
>> eval block.
>
> You may not need an eval block:
>
> perldoc -f alarm
> [ SNIP ]
> If you want to use "alarm" to time out a system call you
> need to use an "eval"/"die" pair. You can’t rely on the
> alarm causing the system call to fail with $! set to "EINTR"
> because Perl sets up signal handlers to restart system calls
> on some systems. Using "eval"/"die" always works, modulo
> the caveats given in "Signals" in perlipc.
>
>
> And besides, an eval with a block is compiled at the same time as the rest
> of your program and doesn't have the run-time overhead of a string eval.
>
So basically I could create my Signalhandler for the alarm signal, do
my calculations in the signalhandler and then start another alarm()?
$SIG{ALRM} = {
# do stuff
alarm($timeout_2);
};
alarm $timeout_1;
And in case this works, is it a good and stable way to solve my problem?
david
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/