[Date Prev][Date Next][Thread Prev][Thread Next]
[Search]
[Date Index]
[Thread Index]
Re: [MacPerl] sleep vs. other method
At 1:49 PM -0500 9/17/99, Jefferson R. Lowrey wrote:
>I could very easily increase the sleep time. I am also looking into other
>ways of telling if the installs I'm looking at are finished - because
>waiting until the log doesn't change any more is not a great way to do it,
>as it might potentially never stop changing. That's not very likely, and
>watching the log is the most straightforward method, I think.
I'm a big fan of alarm() for preventing runaway processes.
Here's an example of some code I use to check for the existence
of an html file before proceeding
Roughly...
#!perl
use LWP::Simple qw(get);
$SIG{ALRM} = sub {die "timesup\n";};
eval {
alarm(45);
while (! defined ($check_url = get($url))) {sleep 5;}
alarm(0);
};
if ($@ =~ /timesup/) {
### couldn't find the html file in the allotted time
...
} elsif ($@) { #some other error happened
alarm(0); #clear the alarm
die; #and die
} else {
### the file is there, so do something about it
...
}
__END__
Without the alarm(), the script would just happly keep looking
for the file every five seconds. With the alarm, I can set a
limit on how long it can continue checking, in this case 45
seconds.
Maybe you could do something similar with your script. Wrap
your while loop with an eval block an alarms and then check for
the timeout condition afterwards and handle accordingly.
See also _Perl_Cookbook_ recipe 16.21 Timing out an Operation.
(_Perl_Cookbook_ is ISBN # 1-56592-243-3. If you don't have a
copy, get one.)
One other thought. Does NetOctopus quit when it's finished.
You could...
use Mac::Apps::Launch;
IsRunning($NetOctapus);
-Eric
===== Want to unsubscribe from this list? ===== Send mail with body "unsubscribe" to macperl-request@macperl.org