|
ru.perl- RU.PERL ---------------------------------------------------------------------- From : Peter B. Shalimoff 2:5020/400 18 May 2005 17:20:39 To : Maxim Yemelyanov Subject : Re: DBI и threads -------------------------------------------------------------------------------- Maxim Yemelyanov wrote: > Еще можно написать письмо авторам DBD::mysql с соответствующей просьбой > (добавить CLONE). Я так сделал для DBD::InterBase. Обновил с CVS-a. По-прежнему не работает. Что я делаю не так? X:\MYDOCS\Perl>perl -version This is perl, v5.8.4 built for MSWin32-x86-multi-thread (with 3 registered patches, see perl -V for more detail) Copyright 1987-2004, Larry Wall Binary build 810 provided by ActiveState Corp. http://www.ActiveState.com ActiveState is a division of Sophos. Built Jun 1 2004 11:52:21 === ib_thread_test.pl === use strict; use warnings; use DBI; use threads; my $g_dbh; sub getDSN() { return <<DSN dbi:InterBase:database=D:\\TEMP\\test.gdb; host=localhost; ib_dialect=3; DSN } sub getUsername() { return "sysdba"; } sub getPassword() { return "masterkey"; } sub getDBConnection() { if ( defined($g_dbh) ) { printf("getDBConnection: returning existing connection\n"); return $g_dbh; } my %attrs = (PrintError => 0, RaiseError => 1, AutoCommit => 0, ib_timestampformat => "%d.%m.%Y %H:%M", ib_dateformat => "%d.%m.%Y", ib_timeformat => "%H:%M" ); $g_dbh = DBI->connect(getDSN(), getUsername(), getPassword(), \%attrs); } sub thread_func { printf("thread_func: getting DB connection\n"); my ($dbh, $sth); eval { $dbh = getDBConnection(); $sth = $dbh->prepare("select count(*) from Q"); // line 38 }; if ( $@ ) { printf("Fuck: %s\n", $@); } if ( defined($sth) ) { $sth->finish(); } printf("thread_func: we're OUT\n"); } sub main() { my $dbh = getDBConnection(); my $sth = $dbh->prepare("select count(*) from Q"); $sth->finish(); my $t = threads->create(\&thread_func); $t->join(); printf("main: we're OUT\n"); } main(); Выхлоп: X:\MYDOCS\Perl>ib_thread_test.pl thread_func: getting DB connection getDBConnection: returning existing connection Fuck: DBD::InterBase::db prepare failed: handle 2 is owned by thread 15d4a34 not current thread 1c1f2a4 (handles can't be shared between threads and your driver may need a CLONE method added) at X:\MYDOCS\Perl\ib_thread_test.pl line 38. thread_func: we're OUT main: we're OUT -- 0xdeadbeef --- ifmail v.2.15dev5.3 * Origin: Sweet Home (2:5020/400) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.perl/63591ac8d133.html, оценка из 5, голосов 10
|