watching worker time processes
rahed
raherh at gmail.com
Wed Mar 11 15:22:16 CET 2015
Hi,
I want to start several processes in parallel and gather data from them
in a parent. Would like to use an RPC protocol with probably
AnyEvent::Fork::Pool. Each process must take maximum time to
execute. I'm new to event programming, normally I would watch for ALRM
signal in eval with alarm function set for maximum time to elapse.
I tried the following, initially for one process, mostly from
AnyEvent::Fork::RPC docs. When timer is fired I'd like the child to
finish/exit. Or should I use something else instead of timer?
use AnyEvent;
use AnyEvent::Fork;
use AnyEvent::Fork::RPC;
$done = AE::cv;
$fork = AnyEvent::Fork
->new
->require ("AnyEvent::Fork::RPC::Async")
->eval (do { local $/; <DATA> });
$rpc = $fork->AnyEvent::Fork::RPC::run ('myworker',
async => 1,
on_error => sub { warn "ERROR: $_[0]"; exit 1 },
on_event => sub { print $_[0] },
on_destroy => $done,
);
$rpc->(sub {
$child_data = shift;
warn "PARENT: job finished\n";
});
undef $rpc;
$done->recv;
__DATA__
use AnyEvent;
sub myworker {
$done = shift;
$w = AE::timer 10, 0, sub {
$mytime = time;
AnyEvent::Fork::RPC::event "timeout at $mytime\n";
undef $w;
# $done->();
};
# ... time consuming code gathering $data, generally under timer period
$done->($data);
}
Thank you and regards
--
Radek
More information about the anyevent
mailing list