There's more than one way to do things | |
PerlMonks |
Alternatives to Mixing Alarm and Sleepby pileofrogs (Priest) |
on Feb 19, 2010 at 23:34 UTC ( [id://824281]=perlquestion: print w/replies, xml ) | Need Help?? |
pileofrogs has asked for the wisdom of the Perl Monks concerning the following question: Greetings ye Monks. I have a loop that sleeps at the end and I want to make the thing bail out if the whole loop takes too long. The obvious solution:
... is bad because perlfunc says: It is usually a mistake to intermix "alarm" and "sleep" calls. ("sleep" may be internally implemented in your system with "alarm") So what's the "right" way to do this? Do I want to fork off a watcher process? Is there a simpler way? If there isn't a simpler way, is there a good CPAN module that handles this? For background: I'm writing an apache log rotater. I want to compress the files once apache has stopped writing to them, which is what is_it_done_yet() is analogous to. My script checks to see if it can start compressing by using lsof (Unix::Lsof) and compresses them using gzip if it can. If lsof or gzip wander off and never return, I want to have some way to abort the whole thing. Thanks!
Back to
Seekers of Perl Wisdom
|
|