use DBI; use POE; my $dbh = DBI->connect('dbi:mysql:****', '****', '****', {RaiseError => 1}); POE::Session->create(inline_states => {_start => \&tester}, heap => {dbh => $dbh->clone()}); POE::Session->create(inline_states => {_start => \&tester}, heap => {dbh => $dbh->clone()}); POE::Kernel->run(); sub tester { my $heap = $_[HEAP]; for my $key (@{$heap->{dbh}->selectcol_arrayref("SELECT id, sleep(0.1) FROM mytable WHERE 1")}) { print $key; } } #### my @threads; for my $i (1..2) { push @threads, threads->create(\&testsub, $dbh->clone()); } foreach my $thread (@threads) { $thread->join(); } sub testsub { for my $key (@{$_[0]->selectcol_arrayref("SELECT id, sleep(0.1) FROM keywords WHERE 1")}) { print $key; } }