Like some of you who have posted here, I have experienced frustrating
problems with LWP timeouts and eval die()'s. Sometimes they work, and
sometimes the queries take much longer than I'm specifying. Marc
Langheinrich and others have suggested solutions but my attempts to
implement them have not yet succeeded. As a final, desperate plea I am
posting a brief code excerpt below and hoping that someone on this list can
suggest a solution.
---------code excerpt-----------
--------- Platform: Linux, Perl 5.005_03, LWP 2.39
use strict;
use LWP::Parallel::UserAgent qw(:CALLBACK);
my $agent = new LWP::Parallel::UserAgent;
$agent->env_proxy;
$agent->redirect(1);
$agent->max_hosts(5);
$agent->max_req(5);
$agent->timeout(10);
## previously attempted to add $agent->use_eval(0) but that didn't fix the
problem
sub response_handler {
my ($content, $response, $protocol, $entry) = @_;
## ... handler code that occasionally returns C_ENDALL;
return undef;
}
my $this_url;
foreach $this_url (@urls) {
my $request = new HTTP::Request('GET', $this_url);
$agent->register($request, \&response_handler, 4096);
}
$SIG{ALRM} = sub {
if ($should_continue) {
alarm(5);
} else {
die "timeout";
}
}
eval {
alarm(5);
my $response = $agent->wait();
alarm(0);
};
print "Done.";
------------------------------
As you can see I'm trying in a number of ways to abort the requests if
they're taking too long. I'm setting the $agent's timeout, I'm executing the
code within an eval() and setting an alarm that either calls die() or resets
the alarm, I'm returning C_ENDALL at some points (and undef at other times),
and I briefly but unsuccessfully added the line $agent->use_eval(0);.
Most of the time this works properly, but as much as 20% of the time the
requests will take a very long time to return--much longer than I'm
specifying.
Many thanks,
David
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com