[CDBI] Class:DBI::Loader, Net::Daemon, threads and... ewww... :)

Mike Whitaker mike at mindcandydesign.com
Tue Sep 27 08:39:38 BST 2005

On 26 Sep 2005, at 23:52, Matt S Trout wrote:

>> OK. Fair enough. I'm probably being naughty. But is there a way of
>> preserving the Class::DBI::Loader constructed relationships and
>> hooking a new DBI handle on the back end?
> Simple. Immediately after the loader's done it's job, call
> CDBIBase->db_Main->disconnect; # Where your tables are CDBIBase::Table
> That'll disconnect the stored dbh. Provided nothing touches the db  
> between
> then and when you spawn the threads that do the work, the first db  
> operation
> each thread initiates will connect its own dbh and you should be fine.

Nothing can, 'cause all the DB calls are caused to happen by talking  
to the daemon :)

> This certainly works ok in a fork/exec environment, but there may  
> be caveats
> under threading that I'm not aware of. Give it a go and tell us how  
> you get
> on :)

Here goes...


My tables all use additional_base_classes Foo::Base.
Both Foo::Base->db_Main->disconnect and Foo->db_main->disconnect give  
me 'Can't locate object method "db_Main" via package "Foo"' (or  

$loader->find_class('a_class')->db_Main->disconnect works, but I  
still get the:

DBD::mysql::db FETCH failed: handle 2 is owned by thread 814c008 not  
current thread 8ea9130 (handles can't be shared between threads and  
your driver may need a CLONE method added) at /usr/share/perl5/Ima/ 
DBI.pm line 316, <GEN12> line 2.

*scratches head*

More information about the ClassDBI mailing list