in reply to Splitting one large timeout into few smaller ones..

How about the alarm solution, without the forking?
$SIG{ALRM} = sub { die "Timed out"; # Or whatever } foreach $task (@tasks) { alarm 30; $task->do_one_task(); }; alarm 0; $SIG{ALRM} = 'DEFAULT';

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Splitting one large timeout into few smaller ones..
by Eyck (Priest) on Apr 07, 2005 at 20:10 UTC

    Yeah, that would be exactly what I was asking about, I just hoped for something less dramatical (without die), but that's good enough, I can always wrap all that code in eval and just catch this 'die'.

    Thanks.

    Interestingly this works well with Event, I was affraid it wouldn't (Event uses timeout handling written in C, but it seems like it's alarm based). Here's the final code:

    use Event; use Event::Stats; Event::Stats::enforce_max_callback_time(1); sub callback { for (1..int(rand(999))) { alarm(10); sleep 2;#relatively long running tast }; }; $Event::DIED = sub { Event::verbose_exception_handler(@_); Event::unloop_all(); }; # just die Event->idle(min=>1,max=>2,cb=> \&callback,max_cb_tm=>10,); Event::loop();