[Gllug] Re: Timeouts in perl
- Tethys
tethys at gmail.com
Mon Nov 6 13:08:23 UTC 2006
On 10/31/06, - Tethys <tethys at gmail.com> wrote:
> However, the exception triggered by the die call is not being
> caught by the eval. Do I need to do something explicit to propagate
> the exception up the calling stack? It works if the code is inside the
> eval itself, rather than in a separate function called from within the
> eval. But that tends to default the whole point of the exercise.
Hmmm. No one actually answered this, but I have made some progress. My
code works perfectly, except for when the long operation is a
WWW::Mechanize request. Thanks to Robert McKay who first spotted that.
It doesn't matter whether I use my own timeout routine or Time::Out as
suggested by a couple of people. So, what is WWW::Mechanize doing to
screw up my exception handling, and what can I do to get around it?
Here's a sample program that demonstrates timeouts failing with
WWW::Mechanize:
#!/usr/bin/perl -w
use strict;
use warnings;
use WWW::Mechanize;
use Time::Out;
################################################################
sub timeout_test
{
my $mech = shift;
my $count = 0;
while ($count < 25)
{
my $url = sprintf("http://www.microsoft.com/?q=%d", $count);
print "fetching $url\n";
$mech->get($url);
$count++;
}
}
################################################################
my $mech = WWW::Mechanize->new(stack_depth => 1);
timeout 5 => affects { timeout_test($mech); };
print "timed out\n" if ($@);
Any ideas?
Thanks,
Tet
--
Gllug mailing list - Gllug at gllug.org.uk
http://lists.gllug.org.uk/mailman/listinfo/gllug
More information about the GLLUG
mailing list