in reply to Re^2: Splitting one large timeout into few smaller ones..
in thread Splitting one large timeout into few smaller ones..

I didn't suggest you reorder tasks. You fork and wait. If the wait times out, you kill the child and error out. You only have one spawned sub-process at a time.

Update: you'd have to rig up the timeout yourself, depending on what your system supports. You want to poll and sleep until the process completes, or until you've waited long enough for it. Or you could set an alarm, do a wait, and if the wait returns, unset the alarm.


Caution: Contents may have been coded under pressure.
  • Comment on Re^3: Splitting one large timeout into few smaller ones..

Replies are listed 'Best First'.
Re^4: Splitting one large timeout into few smaller ones..
by Eyck (Priest) on Apr 07, 2005 at 15:13 UTC
    Please provide sample code/pseudocode, because I don't quite follow. Here's how it looks right now:
    Event->idle(min=>$mint,max=>$maxt, cb=> [$sth,"method"], max_cb_tm=>$timeout,);
    where $timeout is my large timeout value, roughly every $mint seconds $sth->method() is called, if it takes longer then $timeout it is killed off.

    I don't know where am I supposed to fork.

      You would fork inside your
      foreach $task (@tasks) { $task->do_one_task() };
      It might go like this (see fork for more error checking):
      foreach $task (@tasks) { use POSIX ':sys_wait_h'; my $child = fork(); if ($child) { for (my $polls = 30; waitpid($child, WNOHANG) == 0; --$polls) +{ if ($polls < 1) { print "Game over...killing $child\n"; kill 'ABRT', $child; # Maybe return some code, or exit here } sleep 1; } } else { $task->do_one_task() exit 0; } }
      or, probably better:
      my $child = fork(); if ($child) { $SIG{ALRM} = sub { print "Game over...killing $child\n"; kill 'ABRT', $child; # Maybe return some code, or exit here }; alarm 10; # Waiting for child or alarm waitpid($child, 0); } else { $task->do_one_task() exit 0; }

      Caution: Contents may have been coded under pressure.