in reply to Parllel Processing Database Query

I've seen that error before when using DBI and Parallel::ForkManager. The problem arises when a $dbh is inherited from the parent, and several childs try to use the same connection at the same time. I solved this as follow:
my $fork_manager = new Parallel::ForkManager(10); $fork_manager->start and next; # fork # Clone parent dbh my $dbh_child = $dbh->clone(); $dbh->{InactiveDestroy} = 1; $dbh = $dbh_child;
So you can try:
sub db_execution { ... my $dbh = $db->connect( 'students' ) or die $!; my $dbh_child = $dbh->clone(); $dbh->{InactiveDestroy} = 1; $dbh = $dbh_child; my $sth = $dbh->prepare( $sql ) or die "$!:" . $dbh->errstr; $sth->execute or die "$!:" . $sth->errstr; ... }
Hope this helps

Replies are listed 'Best First'.
Re^2: Parllel Processing Database Query
by whakka (Hermit) on Jul 29, 2009 at 13:31 UTC