Oh didn't realize that DBIx is direct subclass, so I can use all the methods of DBI. Anyway I changed the script accordingly (using just one $dbh DBIx Threaded object), and instead of the async methods I use regular ones, but now the problem is that script isn't able make use of more then one connection, so after one thread is created and detached, the second throws fatal error, as it is unable 'prepare' the statement and return $sth object...
my $dbh = DBIx::Threaded->connect("DBI:mysql:database=$database;host=$ +host", $user, $password); DBIx::Threaded->dbix_threaded_create_pool(10); my $sth = $dbh->prepare("SELECT id,domain,DATE(created) FROM domain_li +st"); $sth->execute(); my $counter = 0; while (my @row = $sth->fetchrow_array()) { my $id = $row[0]; my $domain = $row[1]; my $created = $row[2]; next unless $row[0..3]; my $thr = threads->create(mx_lookup,$id,$domain,$created,$dbh) unl +ess $counter >= $thread_no; $thr->detach && $counter++ if $thr; } $sth->finish(); sub mx_lookup { my $id = shift; my $domain = shift; my $date_c = shift; my @date_c = split /-/, $date_c; my $delta = Delta_Days(@date_c,@date); my %emails_in; my %emails_out; if ($delta <= 30) { my @mx = mx($domain); #add multiple mxs support here my $mx_count = @mx; my $mx = $mx[0]->exchange; #find the last change for the given domain my $sth = $dbh->prepare("select max(id),domain_id,changed_from +,changed_to,date from mx_history where domain_id=?"); #this is where +the script fails $sth->execute($id); my @row = $sth->fetchrow_array(); $sth->finish(); } }
And $dbh->errstr is -->
Thread 43 terminated abnormally: Error:Unexpected db_prepare request: +must be connected to do that.
seems like that the $dbh handle isn't conected at all...

In reply to Re^4: Threads and multiple DBI connections by clone4
in thread Threads and multiple DBI connections by clone4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.