AnyEvent::Fork clarification

Marc Lehmann schmorp at schmorp.de
Sat Jan 11 10:41:32 CET 2014


On Thu, Jan 09, 2014 at 12:00:50AM -0500, Vikas N Kumar <vikas at vikaskumar.org> wrote:
> - the GUI is responsive but the AnyEvent forks don't happen. On running
> "ps x" you can see AnyEvent::Fork/exec of $PID and AnyEvent::Fork of
> $PID but the actual non-perl processes that were supposed to be forked
> were not seen. The unit-test on the other hand does this just fine
> 
> - the GUI is able to fork if AnyEvent->condvar->recv is called on the
> button click but this causes the processes to complete but hang around
> as zombies unless the whole GUI process exits.
> 
> How do I go about fixing these problems or finding ways to debug what is
> happening ?

As for zombies, unless you force it, AnyEvent::Fork will only fork one
process, which then sets SIGCHLD to IGNORE. all other processes are then
forked from this process (which itself does not exit), so it should be
quite hard to get any zombies. The zombies are children of which process?

When you use ->run, then this no longer applies, so if you fork children form
your anyevent::fork processes, nothing will clean them up for you, but it
doesn't sound as if this is your problem.

That condvar->recv works probably indicates yet another error in POE -
apparently, you probably still need POE to take over the process. What
happens when you do something like:

   POE::Kernel->run;

instead of run Prima? That would run POE as main event loop, which might
fix things (anyevent shouldn't worry either way).

> Ok. So the problem is POE::Loop::Prima. It is not handling
> AnyEvent::Fork when "run Prima" is called. I had to force Prima to use
> EV as the loop and call Prima;:Application->yield in a timer. I could
> then replace "run Prima" with an AnyEvent->condvar->recv call and things
> work fine.

Not good. The only thing AnyEvent::Fork relies on is I/O watchers.

I guess the right thing to do would be to write an anyevent backend
for Prima. I don't remember what my problems were when I attempted this long
ago, I think I just couldn't get Prima to work for me.

From a cursory look at the docs, it should be relatively straightforward to
write an adapter. I might make an attempt (if I get Prima to work), but I
can't really promise any timeframe.

> > - the GUI is able to fork if AnyEvent->condvar->recv is called on the
> > button click but this causes the processes to complete but hang around
> > as zombies unless the whole GUI process exits.
> I had to just delete the AnyEvent::Fork object which I was storing in a
> hash to access from elsewhere. Once this deletion is done, I can
> recreate it later and it still works.

Interesting - AnyEvent::Fork literally does no cleaning up whatsoever (it
doesn't even have a destructor and after the run callback is invoked it will
clear @$self), so all that would clean up is an empty blessed array.

Maybe you die in the callback somewhere and your event loop silently ignores
that? That would skip the cleanup and would cause the fork object to keep
references to the file handle and watcher.

On the other hand, the fork object is useless once run is called, so
getting rid of that is the way to go.

-- 
                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