forking and using MySQL

J

James

Hi,

I want to use $dbh to fetch some data from a MySQL database and then
based on that data, fork off another process to work on that data, but

I get the following error messages and then Perl crashes when running
"main.pl".

Does anyone have any ideas on how to fix this problem?

The output of the program should be:
this is the output!

Any help much will be much appreciated. Cheers!

=====================================
W:\libs>perl main.pl
Use of uninitialized value in print at Gen.pm line 17.
Attempt to free non-existent shared string.
Attempt to free non-existent shared string.
Attempt to free non-existent shared string during global destruction.Issuing rollback() for database handle being DESTROY'd without
explicit disconne
ct().
(in cleanup) panic: DBI active kids (-2) < 0 or > kids (0).
DBI handle cleared whilst still active.
(in cleanup) panic: DBI active kids (-3) < 0 or > kids (0).


-----------------
File: myModule.pm
-----------------

#!/perl/bin/perl
package myModule;
require Exporter;
@ISA = (Exporter);
use Gen;
use Mysql;
sub getOutput() {
my $OUTPUT = "this is the output!\n";
return $OUTPUT;
}

1
;

------------
File: Gen.pm
------------
#!/perl/bin/perl
package Gen;
require Exporter;
@ISA = (Exporter);

sub runPacket() {
my $packet = $_[1];
my $output = "";
my $isparent = 1;
my $newpid = fork();
if ($newpid==0) {
my $load = "${PACKETDIR}\:\:${packet}Lib";
$isparent = 0;
eval "require $load";
my ($cond) = eval "${packet}Lib->getOutput();";
open (OUTPUT, ">$$.tmp");
print OUTPUT $cond;
close (OUTPUT);
}
if (!($isparent)) {
exit ( 0 );
} else {
waitpid ($newpid, 0);
open (INPUT, "$newpid.tmp");
while (<INPUT>) { $output .= $_; }
close (INPUT);
unlink "$newpid.tmp";
}
return $output;
}

1
;

-------------
File: main.pl
-------------
#!/perl/bin/perl -w
require Gen;
use Mysql;
my $dbh = Mysql->connect ("localhost", "testdb", "", "");
$output = Gen->runPacket ("myModule");
print "> $output\n";
 
M

Mothra

Try adding the -w switch to your header line and the strict pragma to
your code. Then run it through the perl debugger and you should be able
to see what is going wrong..

Presumably this line is not returning anything to $cond:

my ($cond) = eval "${packet}Lib->getOutput();";

those parentheses around $cond are redundant too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top