List:General Discussion« Previous MessageNext Message »
From:Gord Shier Date:April 4 1999 2:15am
Subject:DBI + fork + db handles
View as plain text  
Hi.

I am using Perl DBI and MySQL.  My program does some 
processing on the database, and then splits into a number of 
children that each process a small bit while the parent waits for 
them all.


a (hopefully not too) trivialized outline:
----------------------------------
$dbh = DBI->connect(...
$dbh->do(...
$dbh->do(...
for ($i=0; $i<5; $i++) {
  $pid = fork;
  if ($pid>0) {
    #child processing goes here
    $dbh->do(...
    $dbh->do(...
    $dbh->do(...
    exit 0;
    }
  }

do {
  $pid = wait;
  } until ($pid<0);

$dbh->do(...
$dbh->do(...
$dbh->disconnect;
exit 0;
----------------------------------

My problem is that the children inherit the database handle, and 
when they exit, they close it.  If they do that, the parent no longer 
has a valid handle.

Is there a way to tell the children to not close a database handle?  
If there is, then I could let each child open its own connection.  
Otherwise, I think I'll have to close the parent connection before the 
forking, and then have each child and the parent all open new 
connections.

Best regards to all (especially Monty and the MySQL gang!)
Gord Shier
shier@stripped
Thread
DBI + fork + db handlesGord Shier4 Apr
  • Re: DBI + fork + db handlesSasha Pachev4 Apr