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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.