Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perlmonks I'm using Parallel::ForkManager to send e-mails as follows:
my $pm = new Parallel::ForkManager(4); foreach my $bccperson (@bccppl) { if ($xcount > 49) { sleep 5; $xcount = 0; } $pm->run_on_start( sub { $scount++; print "Sending Msg:$mjobno:$scount:$bccperson\n"; } ); $pm->run_on_finish( sub { $xcount++; } ); my $pid = $pm->start and next; my $msg = MIME::Lite->new( From => $from, To => $bccperson, Subject => $subject, #Type => 'text/html', Type => 'text', Data => $body ) || print "MIME::Lite new error: $bc +cperson\n"; #$msg->print_body; MIME::Lite->send('smtp', '10.10.10.10', Timeout=>240); $msg->send() || print "Couldn't send to: $bccperson\n"; $pm->finish; } #End of foreach $bccperson $pm->wait_all_children; print "Connecting for insert into jobs_run: JOBNO:$mjobno\n"; my $sql4 = qq { insert into jobs_run (jobname, datein, howmany, error +mesg) values ( 'attachmailer', sysdate, $scount, 'JOBNO:$mjobno')} | +| warn "Error: $!\n"; print "preparing Query"; my $sth4 = $dbh->prepare( $sql4 ) || warn "Prepare Error: $!\n"; print "executing Query"; $sth4->execute() || warn "Execute Error: $!\n"; print "Done";
The code runs fine, but it doesn't run any of the SQL statements, if I remove the Parallel::ForkManager stuff, it runs fine. Hope the monks know :-)

Replies are listed 'Best First'.
Re: Parallel::ForkManager - doesn't run code after
by kvale (Monsignor) on Jun 28, 2002 at 15:44 UTC
    I'm not familiar with Parallel::ForkManager, but one problem is that I don't see where the instance  $dbh is being created:
    my $sth4 = $dbh->prepare( $sql4 ) || warn "Prepare Error: $!\n";
    -Mark
      Hi, $dbh does exist & was created earlier, it definately works as I retrieve data via it earlier in the script, if I replace the following code
      ------------------------------------------ } $pm->wait_all_children; print "Connecting for insert into jobs_run: JOBNO:$mjobno\n"; my $sql4 = qq { insert into jobs_run (jobname, datein, howmany, error +mesg) values ( 'attachmailer', sysdate, $scount, 'JOBNO:$mjobno')} | +| warn "Error: $!\n"; print "preparing Query"; my $sth4 = $dbh->prepare( $sql4 ) || warn "Prepare Error: $!\n"; print "executing Query"; $sth4->execute() || warn "Execute Error: $!\n"; print "Done"; ------------------------------------------
      with simple
      ------------------------------------------ print "Preparing Query"; print "Hello World\n"; ------------------------------------------
      it won't print "Hello World" or anything other command after that, but it will print "Preparing Query" which ||'s nothing. It's definately related to the ForkManager stuff, because if I comment it all out, everything works fine (except for not using the ForkManager stuff)