Just an idea. Or a study or a sketch. As you like:

#!/usr/bin/env perl use strict; use warnings; use threads; use MCE::Hobo; use MCE::Shared; use DBI; use Data::Dump; use feature qw(say); use constant AMOUNT => 1; use constant MAX => 100; use constant DB => qq(dbi:SQLite:testomato.db); say qq($0 $$); sleep AMOUNT; my $shared = MCE::Shared->array(); my $cores = MCE::Util::get_ncpu(); MCE::Hobo->init( max_workers => $cores ); for my $id ( 1 .. MAX ) { my $hobo = MCE::Hobo->create( \&task ); say qq( $id ) . $hobo -> pid(); } MCE::Hobo->wait_all(); my $result = $shared->export; dd $result; sub task { my $db = DBI->connect( DB, "", "") or die DBI->errstr; my $result = $db->selectall_arrayref("SELECT * FROM fubar"); $db -> disconnect; $shared -> push($result); sleep AMOUNT; } __END__

The flow can be nicely observed in the process table.

Here is how to generate the example db:

Karls-Mac-mini:db karl$ sqlite3 testomato.db "create table if not exis +ts fubar(id INTEGER PRIMARY KEY, name TEXT, surname TEXT);" Karls-Mac-mini:db karl$ sqlite3 testomato.db "insert into fubar (name, + surname) values ('karl','goethebier');" Karls-Mac-mini:db karl$ sqlite3 testomato.db "select * from fubar"; 1|karl|goethebier Karls-Mac-mini:db karl$

As i don't have Postgres on my box and i don't want it i used SQLite to show the basic idea. A database is a database. I don't know if this example is helpful. But i guess at least it might be interesting. Best regards.

«The Crux of the Biscuit is the Apostrophe»


In reply to Re: Can't get multiple Parallel::ForkManager threads connecting to DBD::Pg database by karlgoethebier
in thread Can't get multiple Parallel::ForkManager threads connecting to DBD::Pg database by perlygapes

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.