http://qs321.pair.com?node_id=193551

arashi has asked for the wisdom of the Perl Monks concerning the following question:

I'm using the Geo::WeatherNWS module to get METAR data, and it works fine...for the most part. Sometimes when trying to access the server, the script will hang and there doesn't seem to be any timeout check in the module. Is there something I can do that would allow me to set a timeout for the script, so it doesn't hang (I'll probably use the last good values if it fails)?
#!/usr/bin/perl -w use strict; use Geo::WeatherNWS; my $Report=Geo::WeatherNWS::new(); $Report->setservername("weather.noaa.gov"); $Report->setusername("anonymous"); $Report->setpassword('anemailuser@adomain.com'); $Report->setdirectory("/data/observations/metar/stations"); $Report->getreport('kmrj'); print $report;
Thanks in advance for your help
Arashi

Replies are listed 'Best First'.
Re: WeatherNWS Timeout
by BrowserUk (Patriarch) on Aug 28, 2002 at 19:44 UTC

    Geo::WeatherNWS uses NET::ftp, and that has an optional timeout setting which defaults to 120 seconds.

    You might need to dig into the source of Geo::WeatherNWS and adjust or add this setting to some reasonable value for your needs.

    Or you could cantact the authors and ask them to make an adjustment, or offer them a patch if your confident enough to try that.


    What's this about a "crooked mitre"? I'm good at woodwork!
Re: WeatherNWS Timeout
by fglock (Vicar) on Aug 28, 2002 at 19:38 UTC

    perldoc perlipc shows how to setup a timeout (It might not work in Windows):

    eval { local $SIG{ALRM} = sub { die "alarm clock restart" }; alarm 10; # your code here alarm 0; }; if ($@ and $@ !~ /alarm clock restart/) { die }