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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |