in reply to How to timeout a while loop?
Not tested, but should get you pointed in the right direction. Alarm 0 is important to unset the alarm.$SIG{ALRM} = sub {die 'timeout'}; while ( $number < 10 ) { eval { alarm(3); print $number; if ( $number == 3 ) { sleep 4; } # This is to simulate the delay + the routines may generate... $number++; print "\n"; }; alarm(0); if($@ eq 'timeout') { next; } else { die $@; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to timeout a while loop?
by Andre_br (Pilgrim) on Apr 25, 2005 at 20:36 UTC | |
by suaveant (Parson) on Apr 25, 2005 at 20:47 UTC |