RE: activeperl + mysql + threads = crash
> I thought I can hit a nice milestone today, but it seems that > I have hit > a strange obstacle instead. > In my tests, the following code will run, but when it terminates an > error message will be shown. > use strict; > use warnings; > use DBI; > use threads; > > doIt(); > doIt(); [snip] > Can someone confirm this? Is there anybody who can suggest a > workaround? The following links imply that DBD::mysql is not threadsafe by default due to the underlying C library, but can be made so by recompiling. Not sure whether anyone has any updates on this. http://aspn.activestate.com/ASPN/Mail/Message/perl-DBI-Dev/2241467 http://search.cpan.org/~jwied/Msql-Mysql-modules-1.2219/mysql/lib/DBD/my sql.pm#MULTITHREADING Paul * Gloucester Research Limited believes the information provided herein is reliable. While every care has been taken to ensure accuracy, the information is furnished to the recipients with no warranty as to the completeness and accuracy of its contents and on condition that any errors or omissions shall not be made the basis for any claim, demand or cause for action. * ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: activeperl + mysql + threads = crash
--- Begin Message --- Hello, I made an additional test: Using the code below Perl v5.8.7 does not crash. In the Task Manager I can see that Perl uses 3 threads. With the original code he uses only one thread. --- new code -- use strict; use warnings; use DBI; use threads; print "first\n"; my $thread = threads->new("doIt","argument"); print "scound\n"; my $thread1 = threads->new("doIt","argument"); $thread->join(); $thread1->join(); $thread->detach(); $thread1->detach(); sub doIt { my $Thishost = $ENV{COMPUTERNAME}; my $addr = (gethostbyname($Thishost))[4]; $addr = join(".", unpack("C4", $addr)); my $dsn = "DBI:mysql:database=resources;host=$addr"; my $dbh = DBI->connect($dsn,"user", "password") or die "can not connect to database \n"; # my $dbh = DBI->connect('dbi:mysql:database','user','password'); my $stmt = $dbh->prepare ('select resolution from resources'); $stmt->execute(); while (my $record=$stmt->fetchrow_hashref('NAME_lc')) { } $dbh->disconnect; } --- end new code -- Foo Ji-Haw wrote: Hello Reinhard, Thanks for confirming my concerns. So you say that on 5.6.x it is ok, but not on 5.8.x. But threading + mysql is quite a powerful combination to give up! I wonder if anybody in this mailing list has a workaround/ solution. Reinhard Pagitsch wrote: Hello, I tryed it also with Perl v5.8.7 and had the same prroblem as you, on the 2nd doIt Perl crashes. I also found out that Perl crashes in the DBI.pm sub "disconnect_all". Removing "use threads;" it works. regards, Reinhard Foo Ji-Haw wrote: Hello Reinhard, I am using 5.8.6 of ActivePerl. Thanks for checking out the codes. Reinhard Pagitsch wrote: Hello, Foo Ji-Haw wrote: Hi all, I thought I can hit a nice milestone today, but it seems that I have hit a strange obstacle instead. In my tests, the following code will run, but when it terminates an error message will be shown. use strict; use warnings; use DBI; use threads; doIt(); doIt(); sub doIt { my $dbh = DBI->connect('dbi:mysql:database','username','password'); my $stmt = $dbh->prepare ('select id from tablename'); $stmt->execute(); while (my $record=$stmt->fetchrow_hashref('NAME_lc')) {} } Change the database connection parameters (eg. username, password, table name) to your database. My analysis of the problem is as follows: 1. Using the ODBC driver is ok. I've tested with MSSQL connection and it's fine. 2. The problem lies with using threads alongside DBI. If I take out 'use threads' all is well. 3. There are 2x doIt() calls because it only fails on the second database connection. 4. It seems to be related to fetchrow_hashref(), because if I take that out, all is fine. Can someone confirm this? Is there anybody who can suggest a workaround? Thanks. There is no problem here, Perl v5.6.1. Which Perl version do you use? regards, Reinhard -- QA ISIS Information Systems Austria tel: (+43) 2236 27551 150 Fax: 2236 21081 Visit our web site http://www.isis-papyrus.com --- This e-mail is only intended for the recipient and not legally binding. Unauthorised use, publication, reproduction or disclosure of the content of this e-mail is not permitted. --- --- End Message --- ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: activeperl + mysql + threads = crash
Hello Reinhard, Thanks for confirming my concerns. So you say that on 5.6.x it is ok, but not on 5.8.x. But threading + mysql is quite a powerful combination to give up! I wonder if anybody in this mailing list has a workaround/ solution. Reinhard Pagitsch wrote: Hello, I tryed it also with Perl v5.8.7 and had the same prroblem as you, on the 2nd doIt Perl crashes. I also found out that Perl crashes in the DBI.pm sub "disconnect_all". Removing "use threads;" it works. regards, Reinhard Foo Ji-Haw wrote: Hello Reinhard, I am using 5.8.6 of ActivePerl. Thanks for checking out the codes. Reinhard Pagitsch wrote: Hello, Foo Ji-Haw wrote: Hi all, I thought I can hit a nice milestone today, but it seems that I have hit a strange obstacle instead. In my tests, the following code will run, but when it terminates an error message will be shown. use strict; use warnings; use DBI; use threads; doIt(); doIt(); sub doIt { my $dbh = DBI->connect('dbi:mysql:database','username','password'); my $stmt = $dbh->prepare ('select id from tablename'); $stmt->execute(); while (my $record=$stmt->fetchrow_hashref('NAME_lc')) {} } Change the database connection parameters (eg. username, password, table name) to your database. My analysis of the problem is as follows: 1. Using the ODBC driver is ok. I've tested with MSSQL connection and it's fine. 2. The problem lies with using threads alongside DBI. If I take out 'use threads' all is well. 3. There are 2x doIt() calls because it only fails on the second database connection. 4. It seems to be related to fetchrow_hashref(), because if I take that out, all is fine. Can someone confirm this? Is there anybody who can suggest a workaround? Thanks. There is no problem here, Perl v5.6.1. Which Perl version do you use? regards, Reinhard ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: activeperl + mysql + threads = crash
Hello, I tryed it also with Perl v5.8.7 and had the same prroblem as you, on the 2nd doIt Perl crashes. I also found out that Perl crashes in the DBI.pm sub "disconnect_all". Removing "use threads;" it works. regards, Reinhard Foo Ji-Haw wrote: Hello Reinhard, I am using 5.8.6 of ActivePerl. Thanks for checking out the codes. Reinhard Pagitsch wrote: Hello, Foo Ji-Haw wrote: Hi all, I thought I can hit a nice milestone today, but it seems that I have hit a strange obstacle instead. In my tests, the following code will run, but when it terminates an error message will be shown. use strict; use warnings; use DBI; use threads; doIt(); doIt(); sub doIt { my $dbh = DBI->connect('dbi:mysql:database','username','password'); my $stmt = $dbh->prepare ('select id from tablename'); $stmt->execute(); while (my $record=$stmt->fetchrow_hashref('NAME_lc')) {} } Change the database connection parameters (eg. username, password, table name) to your database. My analysis of the problem is as follows: 1. Using the ODBC driver is ok. I've tested with MSSQL connection and it's fine. 2. The problem lies with using threads alongside DBI. If I take out 'use threads' all is well. 3. There are 2x doIt() calls because it only fails on the second database connection. 4. It seems to be related to fetchrow_hashref(), because if I take that out, all is fine. Can someone confirm this? Is there anybody who can suggest a workaround? Thanks. There is no problem here, Perl v5.6.1. Which Perl version do you use? regards, Reinhard -- QA ISIS Information Systems Austria tel: (+43) 2236 27551 150 Fax: 2236 21081 Visit our web site http://www.isis-papyrus.com --- This e-mail is only intended for the recipient and not legally binding. Unauthorised use, publication, reproduction or disclosure of the content of this e-mail is not permitted. --- ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
activeperl + mysql + threads = crash
Hi all, I thought I can hit a nice milestone today, but it seems that I have hit a strange obstacle instead. In my tests, the following code will run, but when it terminates an error message will be shown. use strict; use warnings; use DBI; use threads; doIt(); doIt(); sub doIt { my $dbh = DBI->connect('dbi:mysql:database','username','password'); my $stmt = $dbh->prepare ('select id from tablename'); $stmt->execute(); while (my $record=$stmt->fetchrow_hashref('NAME_lc')) {} } Change the database connection parameters (eg. username, password, table name) to your database. My analysis of the problem is as follows: 1. Using the ODBC driver is ok. I've tested with MSSQL connection and it's fine. 2. The problem lies with using threads alongside DBI. If I take out 'use threads' all is well. 3. There are 2x doIt() calls because it only fails on the second database connection. 4. It seems to be related to fetchrow_hashref(), because if I take that out, all is fine. Can someone confirm this? Is there anybody who can suggest a workaround? Thanks. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs