Im trying to understand why the following code wont run correctly, when Im using pause instead of sleep and WWW::Curl. This code will loop two times only and it will get stuck no matter how long I will wait. This happens in Linux, FreeBSD. Stuck here means, it does not continue the loop, seems stuck in pause ... Same construct, alarm,pause works fine if I dont use WWW::Curl, for other types of work.
use strict; use warnings; use WWW::Curl::Easy; use POSIX qw(pause); use Time::HiRes qw(time alarm setitimer sleep ITIMER_REAL); use Getopt::Std; ### Process command line args usage() if defined $ARGV[0] and $ARGV[0] eq "--help"; getopts('hvV') or usage(); # process [interval [count]], my ( $interval, $loop_max ); if ( defined $ARGV[0] ) { $interval = $ARGV[0]; $loop_max = defined $ARGV[1] ? $ARGV[1] : 2**32; usage() if $interval == 0; } else { $interval = 1; $loop_max = 1; } ### Variables my $loop = 0; # current loop number # how often do we trigger (seconds)? my $first_interval = $interval; # signal handler is empty $SIG{ALRM} = sub { }; # first value is the initial wait, second is the wait thereafter setitimer( ITIMER_REAL, $first_interval, $interval ); my $http = WWW::Curl::Easy->new(); if (&WWW::Curl::Easy::version() !~ /ssl|nss/i) { die "No SSL support"; } # Get the results while (1) { my $url = "http://kronometrix.org/"; $http->setopt(CURLOPT_URL, $url); my $retcode = $http->perform(); ## Get the results my $response = $http->getinfo(CURLINFO_HTTP_CODE); if ($retcode == 0) { print "Ok, Status: $response\n"; } else { print "Error, Status: $response\n"; } ### Check for end last if ++$loop == $loop_max; ### Interval pause; # sleep $interval; }

and if I replace pause with sleep this works fine. Im using this alarms with timers to trigger certain actions at specific time intervals.

Anyone any ideas why WWW::Curl breaks down on pause or am I using this wrong ?. Many thanks for help.


In reply to WWW::Curl pause conflict by krmx

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.