From: Sasha Pachev Date: April 4 1999 3:42am Subject: Re: DBI + fork + db handles List-Archive: http://lists.mysql.com/mysql/1394 Message-Id: <3706DF95.DCFF6E74@direct1.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Gord Shier wrote: > > 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 > You must connect AFTER you've forked -- Sasha Pachev http://www.sashanet.com