Appropiate Coro/AnyEvent model?
Marc Lehmann
schmorp at schmorp.de
Mon Nov 18 02:13:32 CET 2013
AnyEvent/Coro using 100% cpu without doing anything usually happens when
you have no watchers left and ask them to wait for events - this results
in a livelock (or deadlock if you prefer).
On Sun, Nov 17, 2013 at 09:08:12PM +0100, Mark Lawrence <nomad at null.net> wrote:
> > $self->{interrupt} = rouse_cb;
> > AE::io $self->{child_stdout}, 0, $self->{interrupt};
Here you create a watcher and imemdiately destroy it (it's never stored).
What you want is either:
{
$self->{interrupt} = rouse_cb;
my $w = AE::io $self->{child_stdout}, 0, $self->{interrupt};
Coro::rouse_wait;
}
Or you can use Coro::AnyEvent for more convenience:
Coro::AnyEvent::readable $self->{child_stdout};
I haven't closely looked at your code to se eif its true, but when you
want to exec a child, maybe AnyEvent::Util::run could simplify the job (it
can "send" the output to a handler or a scalar).
> The last thing I want to be doing inside the do_stuff() subroutine is
> waiting on possible errors. There is nothing event based about that
> approach. Waiting on (normal) input (hence the use of Coro) is however
> fine.
You could use a timeout, and with Coro::Anyevent that's rather simply:
Coro::AnyEvent::readable $self->{child_stdout}, 60
or die "no child data received in 60s\n";
> After all of that I guess I can phrase my question better now: Can a
> coro thread stop itself?
Yes, terminate, cancel, die, return from toplevel would all stop it in
some way or another. Your problem is likely elsewhere (i.e. in the events
part).
> Possibly related to this whole issue is the question of why
> Coro::Handle doesn't deal with errors the same way that
> AnyEvent::Handle does. I had been hoping that Coro::Handle would have
> an on_error => sub {} capability.
Coro::Handle isn't event based, it's supposed to emulate perl's
IO::Handle, to allow traditional code to (mostly) run unchanged.
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp at schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
More information about the anyevent
mailing list