I've been encountering a problem where whenever I run some code which makes an LWP request any alarms I set aren't being captured. The process just carries on until something else causes it to die.

I played around a bit, trying to find out what was going on. And came up with the code below for testing the behaviour.

I set an alarm, make a request and then sleep for 10 more seconds than the alarm period.

This gave me the following
Got page
0 seconds left
No Problems
23 wallclock secs ( 0.13 usr + 0.01 sys = 0.14 CPU)

It appears that something to do with LWP has cancelled my alarm.

Any suggestions on fixes/workarounds for this?
My perl versions are:

LWP 5.50
LWP::Authen::Basic undef
LWP::Authen::Digest undef
LWP::Debug undef
LWP::MediaTypes 1.27
LWP::MemberMixin undef
LWP::Protocol 1.36
LWP::Protocol::GHTTP undef
LWP::Protocol::data undef
LWP::Protocol::file undef
LWP::Protocol::ftp undef
LWP::Protocol::gopher undef
LWP::Protocol::http undef
LWP::Protocol::https undef
LWP::Protocol::mailto undef
LWP::Protocol::nntp undef
LWP::RobotUA 1.17
LWP::Simple 1.33
LWP::UserAgent 1.74

IO undef
IO::File 1.06021
IO::Handle 1.1505
IO::Pipe 1.0901
IO::Seekable 1.06
IO::Select 1.10
IO::Socket 1.1603

Thanks in advance for any help.
#!/usr/bin/perl use strict; # set up modules for LWP use LWP::UserAgent; use Benchmark; my $start = new Benchmark; my $url = 'http://www.bbc.co.uk'; #set alarm and sleep times my $alarm = 10; my $sleep = $alarm + 10; #set alarm sig local $@; local $SIG{ALRM} = sub {die "TIMEOUT" }; #start the alarm alarm $alarm; #wrap it in an eval eval{ #do the lwp stuff lwp_post($url); #sleep sleep $sleep; }; #reset alarm my $remaining = alarm 0; print "$remaining seconds left\n"; if ($@) {print "Error Occured [$@]\n";} else {print "No Problems\n";} my $end = new Benchmark; my $elapsed = timediff($end,$start); print timestr($elapsed); sub lwp_post{ my $address = shift; my $headers = new HTTP::Headers(Accept => 'text/plain', 'User-Agent' => 'LWP Test/1.0'); my $url = new URI::URL($address); my $request = new HTTP::Request('GET', $url, $headers); my $ua = new LWP::UserAgent; my $response = $ua->request($request); if ($response->is_success) { print "Got page\n"; } else { print "Failed to get page\n"; } }

In reply to Alarms broken when using LWP by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.