AnyEvent::Fork failed with sysread filehadle
Genban Tade
tadegenban at gmail.com
Thu Mar 24 17:28:36 CET 2016
Hi,
I'm try to use AnyEvent::Fork and here is my test code:
my $cv = AE::cv;
my $l = [];
AnyEvent::Fork
->new
->eval ('
# compile a helper function for later use
sub run {
my $fh = shift;
sleep 10;
}
')
->run ("run", sub {
my ($fh) = @_;
my $n = sysread $fh, my $dummy, 1; # doesn't block here
print $!;
print "$dummy, here\n";
$cv->send;
}
);
my $stderr = $cv->recv;
wish to use sysread to detect the child process exit, expect it will block
until the child exit, but it not, and directly return undef and $! is
"Resource temporarily unavailable"
I also tried replace sysread with a AE io watcher:
my $rw; $rw = AE::io $fh, 0, sub {
print "parent here\n";
print <$fh> . "\n"; # wierd, this line is required
undef $rw;
$cv->send;
};
$l->[0] = $rw;
this works, and print:
parent here
the wierd thing is, the line "print <$fh> . "\n";" must exist, otherwise,
it'll blocked and never print anything.
can you figure out where's wrong in my code?
Regards,
tadegenban
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/anyevent/attachments/20160325/dea53068/attachment.html>
More information about the anyevent
mailing list