am currently working on a project that involves crawling certain websites.

However sometimes my Perl program will get "stuck" on a website for some reason (can't figure out why) and the program will freeze for hours. To get around this I inserted some code to time out on the subroutine that crawls the webpage. The problem with this is that, lets say I set the alarm to 60 sec, most of the time the page will timeout correctly, but occasionally the program will not time out and just sit for hours on end (maybe forever since I usually kill the program).

On the really bad websites the Perl program will just eat through my memory, taking 2.3GB of RAM and 13GB of swap. Also the CPU usage will be high, and my computer will be sluggish. Luckily if it times out all the resources get released quickly.

Is this my code or a Perl issue? What should I correct and why was it causing this problem?

Thanks

Here is my code:

eval { local $SIG{ALRM} = sub { die("alarm\n") }; alarm 60; &parsePageFunction(); alarm 0; };#eval if($@) { if($@ eq "alarm\n") { print("Webpage Timed Out.\n\n"); }#if else { die($@."\n"); }#else }#if


In reply to Perl alarm working intermittently by DigitalBoB12

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.