Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^4: Splitting one large timeout into few smaller ones..

by Eyck (Priest)
on Apr 07, 2005 at 15:13 UTC ( [id://445729]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^5: Splitting one large timeout into few smaller ones..
by Roy Johnson (Monsignor) on Apr 07, 2005 at 15:38 UTC
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://445729]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-20 02:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found