Re: [MacPerl-WebCGI] Timeout period
[email protected] (Greenblatt & Seay) Fri, 23 Feb 2001 21:10:33 +0100
| Newsgroups | perl.macperl.webcgi |
|---|---|
| Message-ID | <l03110700b6bc6ea32454@[216.170.34.21]> |
At 10:59 AM +0100 2001/02/23, Stephen Criddle wrote:
>Is there a way in MacPerl to set a timeout period on a script? So that
>if (for instance), the script hasn't finished within 30 seconds, a timer
>kicks in to jump to an end routine and quit the script? I need this for
>a script which accesses another machine. If the network connection is
>slow, or the remote server goes down after the connection has been
>established, the script waits indefinitely and has to be manually
>stopped. I'd like to do this automatically.
>
>Steve Criddle
Check out "alarm" in perlfunc.pod (use Shuck and do a 'Lookup' on "alarm"
and it'll take you there) and/or try the following code....
#!perl
$SIG{ALRM} = \&done;
alarm(5);
for (;;) {
$localTime = localtime(time);
if ($localTime eq $hold) { next }
print "$localTime\n";
$hold = $localTime;
}
sub done { exit }
__END__
David Seay
http://www.mastercall.com/g-s/