Greetings,

I am trying to set an alarm to stop a script from sending the load on my machine to the moon. I am using Image::Magick::Thumbnail::PDF to create PNG thumbnails of the first page of a bunch of PDF docs.

ImageMagick uses Ghostscript to parse the PDFs and occasionally a PDF will cause one of them problems, causing my script to hang endlessly sending the load really high on the machine (eventually it gets killed actually). When this happens I want to skip that PDF and move on to the next.

This is what I have, but it is not working on start up. If I hit control-c, then it starts doing its thing... why is that? I want this to run as a cron.

foreach my $pdf (@pdfs) { my $png = "/path/to/thumbs/" . $pdf . ".png"; if (!stat($png)) { eval { local $SIG{ALRM} = sub { die "alarm\n" }; alarm(10); create_thumbnail($pdf,$png); alarm(0); print "Created: $pdf\n"; }; if ($@) { die unless $@ eq "alarm\n"; print " >> Timeout On: $pdf\n"; next; } } }

Thanks!


In reply to Setting an alarm by Rodster001

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.