Problems with MySQL and Perl iThreads

Problems with MySQL and Perl iThreads

am 20.09.2003 19:38:05 von Steve Schein

All:

I'm in the process of tracking down a problem I am having with getting a
MySQL 4.0.11x database to work with Perl ithreads. I'm on a Mandrake
v9.1 Linux system with Perl v.5.8 (threads enabled). I have upgraded my
DBI to v1.38. I was able to write a simulation program (code pasted
below) that faithfully reproduced the following error statement after
opening the the second thread:

"thread failed to start: DBD::mysql::dr connect failed: handle 1 is
owned by thread 8454df8 not current thread 86bc3d0 (handles can't be
shared between threads and your driver may need a CLONE method added) at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBI.p m line 585,
<$client> line 1."

Jochen Wiedmann was kind enough to run the test code on his own system
and reported that everything worked fine and recommended I post my situation
to a mailing list in case someone could immediately identify the issue. The DBI
module was downloaded and installed from CPAN using MCPAN.

I'm hoping that someone in this forum will be able to quickly identify
the configuration issues. I've been careful not to pass filehandles in
the design.

Thank you for your thoughts in advance.

Steve



#!/usr/bin/perl -w

# 9/19/03 - Error simulation program for running connections to MySQL on
threads

$|++;
use strict;
use warnings;

use threads;
use DBI;
#use DBD::mysql;

my ($db_name, $db_user, $db_pass, $statement);


#-----------MAIN------------

my $spawn_thr1 = threads->create(\&thread1);

while (1) {} # keep main thread alive


#-----------sub thread1------------


sub thread1 {

my $tid = threads->tid;
print "Opening thread id: $tid\n";

($db_name, $db_user) = qw(db_name_here db_username_here);
$db_pass = "";
my $dbh1 = DBI->connect('dbi:mysql:'.$db_name, $db_user, $db_pass,
{ RaiseError => 1 } );
$statement = "SELECT * FROM subscribers";

my $ary_ref1 = $dbh1->selectall_arrayref($statement);
my @sub_array1 = @$ary_ref1;
my $num_rows1 = @sub_array1;
print "The number of rows in the table are: $num_rows1\n";

my $rc1 = $dbh1->disconnect;

my $spawn_thr2 = threads->create(\&thread2)->detach;


} # end sub thread1


#-----------sub thread2------------

sub thread2 {

my $tid = threads->tid;
print "Opening thread id: $tid\n";

($db_name, $db_user) = qw(db_name_here db_username_here);
$db_pass = "";
my $dbh2 = DBI->connect('dbi:mysql:'.$db_name, $db_user, $db_pass,
{ RaiseError => 1 } );
$statement = "SELECT * FROM subscribers"; #

my $ary_ref2 = $dbh2->selectall_arrayref($statement);

my @sub_array2 = @$ary_ref2;
my $num_rows2 = @sub_array2;
print "The number of rows in the table are: $num_rows2\n";

my $rc2 = $dbh2->disconnect;


} # end sub thread2












All:

I'm in the process of tracking down a problem I am having with getting a
MySQL 4.0.11x database to work with Perl ithreads. I'm on a Mandrake
v9.1 Linux system with Perl v.5.8 (threads enabled). I have upgraded my
DBI to v1.38. I was able to write a simulation program (code pasted
below) that faithfully reproduced the following error statement after
opening the initial the second thread:

"thread failed to start: DBD::mysql::dr connect failed: handle 1 is
owned by thread 8454df8 not current thread 86bc3d0 (handles can't be
shared between threads and your driver may need a CLONE method added) at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBI.p m line 585,
<$client> line 1."

Jochen Wiedmann was kind enough to run the test code on his own system
and reported that everything worked fine and suggested that perhaps I
needed a multi-threaded version of DBI (I'm not sure how to check) but
more importantly recommended I post my situation in this forum in case
someone could immediately identify the issue. The DBI module was
downloaded and installed from CPAN using MCPAN.

I'm hoping that someone in this forum will be able to quickly identify
the configuration issues. I've been careful not to pass filehandles in
the design.

Thank you for your thoughts in advance.

Steve



#!/usr/bin/perl -w

# 9/19/03 - Error simulation program for running connections to MySQL on
threads

$|++;
use strict;
use warnings;

use threads;
use DBI;
#use DBD::mysql;

my ($db_name, $db_user, $db_pass, $statement);


#-----------MAIN------------

my $spawn_thr1 = threads->create(\&thread1);

while (1) {} # keep main thread alive


#-----------sub thread1------------


sub thread1 {

my $tid = threads->tid;
print "Opening thread id: $tid\n";

($db_name, $db_user) = qw(db_name_here db_username_here);
$db_pass = "";
my $dbh1 = DBI->connect('dbi:mysql:'.$db_name, $db_user, $db_pass,
{ RaiseError => 1 } );
$statement = "SELECT * FROM subscribers";

my $ary_ref1 = $dbh1->selectall_arrayref($statement);
my @sub_array1 = @$ary_ref1;
my $num_rows1 = @sub_array1;
print "The number of rows in the table are: $num_rows1\n";

my $rc1 = $dbh1->disconnect;

my $spawn_thr2 = threads->create(\&thread2)->detach;


} # end sub thread1


#-----------sub thread2------------

sub thread2 {

my $tid = threads->tid;
print "Opening thread id: $tid\n";

($db_name, $db_user) = qw(db_name_here db_username_here);
$db_pass = "";
my $dbh2 = DBI->connect('dbi:mysql:'.$db_name, $db_user, $db_pass,
{ RaiseError => 1 } );
$statement = "SELECT * FROM subscribers"; #

my $ary_ref2 = $dbh2->selectall_arrayref($statement);

my @sub_array2 = @$ary_ref2;
my $num_rows2 = @sub_array2;
print "The number of rows in the table are: $num_rows2\n";

my $rc2 = $dbh2->disconnect;


} # end sub thread2













All:

I'm in the process of tracking down a problem I am having with getting a
MySQL 4.0.11x database to work with Perl ithreads. I'm on a Mandrake
v9.1 Linux system with Perl v.5.8 (threads enabled). I have upgraded my
DBI to v1.38. I was able to write a simulation program (code pasted
below) that faithfully reproduced the following error statement after
opening the initial the second thread:

"thread failed to start: DBD::mysql::dr connect failed: handle 1 is
owned by thread 8454df8 not current thread 86bc3d0 (handles can't be
shared between threads and your driver may need a CLONE method added) at
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi/DBI.p m line 585,
<$client> line 1."

Jochen Wiedmann was kind enough to run the test code on his own system
and reported that everything worked fine and suggested that perhaps I
needed a multi-threaded version of DBI (I'm not sure how to check) but
more importantly recommended I post my situation in this forum in case
someone could immediately identify the issue. The DBI module was
downloaded and installed from CPAN using MCPAN.

I'm hoping that someone in this forum will be able to quickly identify
the configuration issues. I've been careful not to pass filehandles in
the design.

Thank you for your thoughts in advance.

Steve



#!/usr/bin/perl -w

# 9/19/03 - Error simulation program for running connections to MySQL on
threads

$|++;
use strict;
use warnings;

use threads;
use DBI;
#use DBD::mysql;

my ($db_name, $db_user, $db_pass, $statement);


#-----------MAIN------------

my $spawn_thr1 = threads->create(\&thread1);

while (1) {} # keep main thread alive


#-----------sub thread1------------


sub thread1 {

my $tid = threads->tid;
print "Opening thread id: $tid\n";

($db_name, $db_user) = qw(db_name_here db_username_here);
$db_pass = "";
my $dbh1 = DBI->connect('dbi:mysql:'.$db_name, $db_user, $db_pass,
{ RaiseError => 1 } );
$statement = "SELECT * FROM subscribers";

my $ary_ref1 = $dbh1->selectall_arrayref($statement);
my @sub_array1 = @$ary_ref1;
my $num_rows1 = @sub_array1;
print "The number of rows in the table are: $num_rows1\n";

my $rc1 = $dbh1->disconnect;

my $spawn_thr2 = threads->create(\&thread2)->detach;


} # end sub thread1


#-----------sub thread2------------

sub thread2 {

my $tid = threads->tid;
print "Opening thread id: $tid\n";

($db_name, $db_user) = qw(db_name_here db_username_here);
$db_pass = "";
my $dbh2 = DBI->connect('dbi:mysql:'.$db_name, $db_user, $db_pass,
{ RaiseError => 1 } );
$statement = "SELECT * FROM subscribers"; #

my $ary_ref2 = $dbh2->selectall_arrayref($statement);

my @sub_array2 = @$ary_ref2;
my $num_rows2 = @sub_array2;
print "The number of rows in the table are: $num_rows2\n";

my $rc2 = $dbh2->disconnect;


} # end sub thread2
















--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org