Hi Leostereo,
Sometimes, a given CPAN module maybe multi-process unsafe regarding DESTROY and END blocks. From testing, that seems to be the case with IO::Socket::INET::Daemon or perhaps a dependency. You were close otherwise.
# change this statement my $pid = $pm->start and next ; # to the following my $pid = $pm->start and return !0 ; # return 1 works too
The code now looks like this.
use POSIX (); ... my $pm = Parallel::ForkManager->new(10); $pm->set_waitpid_blocking_sleep(0); my $host = new IO::Socket::INET::Daemon( host => 'localhost', port => 1000, timeout => 20, callback => { data => \&data, }, ); $host->run; $pm->wait_all_children; sub data{ my ($io, $host) = @_; my $line = $io->getline; return 0 unless $line; chomp($line); if ($line =~ m/$RE{net}{IPv4}{-keep}/) { my $ip = $1; print "I got ip $ip\n"; my $pid = $pm->start and return !0; fork_work($ip); $pm->finish; # not reached due to calling POSIX::_exit } print "not a good line:", $line; return !0; } sub fork_work { my ($ip) = @_; print "working from new child - $ip\n"; # A given CPAN module maybe multi-process unsafe regarding # DESTROY and END blocks. Fortunately, there's a way around it. POSIX::_exit(0); }
Another possibility is having background workers poll the IP from a queue, not shown here due to lack of time.
Regards, Mario
In reply to Re: IO::Socket::INET::Daemon and Parallel::ForkManager working together
by marioroy
in thread IO::Socket::INET::Daemon and Parallel::ForkManager working togheter
by leostereo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |