Don't understand AnyEvent with fork()

Genban Tade tadegenban at gmail.com
Wed Mar 30 04:44:07 CEST 2016


Hi,

I recently worked with AnyEvent very often, it's very nice !

My question is about AnyEvent with fork ( not the module AnyEvent::Fork ),
here is my code:

use AnyEvent;

my $cv = AE::cv;
my $count = 0;
my $w; $w = AE::timer 1, 1, sub {
    print "timer $count \n";
    $count += 1;
};

my $w1; $w1 = AE::timer 4, 0, sub {
    my $pid = fork();
    if ( $pid ) {
        return;

    } else { # child
        sleep 10;
        print "child end\n";
        exit 0;
    }
};

my $w2; $w2 = AE::io \*STDIN, 0, sub {
    print "STDIN readable\n";
    my $msg = <STDIN>;
    print $msg . "\n";
};

$cv->recv;

this will got:
timer 1
timer 2
...
child end

I wondered when it fork a subprocess in callback, the parent process's ENV,
File Descriptor, all things will be copied to subprocess, so the $cv, $w
will be copied too, so I thought the 'event loop' and 'watcher' in main
process will be copied too, but it seems not, there was not timer watch be
trigger in subprocess, what I missed ?

Best Regards
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20160330/eb600bfe/attachment.html>


More information about the anyevent mailing list