forking and using MySQL

From: James (citation78_at_hotmail.com)
Date: 05/15/04


Date: 15 May 2004 00:14:37 -0700

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";



Relevant Pages

  • Re: Fetch 6 records from a table randomly
    ... critical details (e.g. what sort of table? ... "I have a table 'documents' stored in a MySQL database that I'm accessing ... I haven't been able to find a function in Ruby to pick a random element. ...
    (comp.lang.ruby)
  • Re: sarge + postfix + mysql
    ... >So when postfix/courier is doing a mysql database lookup, ... >'vmail' that is only allowed to log in from localhost and has no ... >permissions for accessing the database 'provider'. ...
    (Debian-User)
  • RE: CGI::Session
    ... > some hashes in a MySQL database, ... > other visitor preferences like the font style, colors, font ... > in a MySQL record than the session ID? ... transmitted without the written permission of the copyright owner. ...
    (perl.beginners)
  • Re: sarge + postfix + mysql
    ... If you are using postfix 2.2.x the sintax of the .cf files may be different. ... > So when postfix/courier is doing a mysql database lookup, ... > permissions for accessing the database 'provider'. ...
    (Debian-User)
  • Access XP / MySQL / MyODBC: Access caching system?
    ... While working on an Access UI to a MySQL database (which should be a ... at MySQL through the ODBC link, so I set up a query log for MySQL. ... Scrolling back to #5 makes Access fetch 41 to 50 again. ... Is there some ridiculously failing caching system at work here? ...
    (comp.databases.ms-access)