Главная страница


ru.perl

 
 - RU.PERL ----------------------------------------------------------------------
 From : Anton Potekhin                       2:5020/400     07 May 2005  02:12:36
 To : All
 Subject : DBI и threads
 -------------------------------------------------------------------------------- 
 
 Hello, All!
 
 Вот такой скрипт:
 require 'config';
 use threads;
 use DBI;
 
 $dbh = DBI->connect("DBI:mysql:database=$database;host=$host",
                        $user, $pass) || die writeLog("Database Error.
 Crawler aborted.");
 $thr1 = threads->new(\&sub1);
 $thr2 = threads->new(\&sub2);
 $thr1->join;
 $thr2->join;
 
 sub sub1 {
    $query = "SELECT UNIX_TIMESTAMP()";
    $sth = $dbh->prepare($query) || print("Can't prepare statement:
 $DBI::errstr");
    $sth->execute;
 
 }
 
 sub sub2 {
    $query = "SELECT UNIX_TIMESTAMP()";
    $sth = $dbh->prepare($query) || print("Can't prepare statement:
 $DBI::errstr");
    $sth->execute;
 
 }
 
 при запуске получаю вот такую бяку :
 
 thread failed to start: DBD::mysql::db prepare failed: handle 2 is owned by
 thread 224014
 not current thread 19e537c (handles can't be shared between threads and your
 driver may ne
 ed a CLONE method added) at a.pl line 19.
 thread failed to start: DBD::mysql::db prepare failed: handle 2 is owned by
 thread 224014
 not current thread 1aa69bc (handles can't be shared between threads and your
 driver may ne
 ed a CLONE method added) at a.pl line 26.
 
 Как это лечить ? Пробовал в каждом потоке конектится работает, но не
 подходит... ПРосто предполагается
 запуск большого кол-ва потоков и тогда скрипт начинает работать очень
 медленно из-за большого
 кол-ва конектов к базе...
 With best regards, Anton Potekhin.  E-mail: anton@orbita1.ru
 --- ifmail v.2.15dev5.3
  * Origin: Demos online service (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 DBI и threads   Anton Potekhin   07 May 2005 02:12:36 
 DBI и threads   Ivan Frolkov   07 May 2005 11:34:20 
 DBI и threads   Ivan Frolkov   07 May 2005 18:34:20 
 Re: DBI и threads   Artem Chuprina   08 May 2005 10:57:20 
 Re: DBI и threads   Valentin Nechayev   08 May 2005 11:48:02 
Архивное /ru.perl/657774b40833.html, оценка 3 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional