Rodster001 has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Setting an alarm
by ikegami (Patriarch) on Mar 10, 2010 at 01:39 UTC | |
by Rodster001 (Pilgrim) on Mar 10, 2010 at 17:10 UTC | |
by ikegami (Patriarch) on Mar 10, 2010 at 17:34 UTC | |
by Rodster001 (Pilgrim) on Mar 10, 2010 at 17:59 UTC | |
by ikegami (Patriarch) on Mar 10, 2010 at 18:37 UTC |