FloydATC has asked for the wisdom of the Perl Monks concerning the following question:
I thought I had avoided the potential problems involved with sharing a handle between processes, but much to my surprise ActivePerl on WinXP crashes when the child tries to connect:use DBI; while (1) { my $dbh = DBI->connect(); # Parent connecting # .. get a job list .. $dbh->disconnect(); # <-- NB! foreach my $job (@jobs) { my $pid = fork(); if (defined $pid) { if ($pid) { $children{$pid} = time; # This is the parent } else { child($job); # This is the child process } } else { logmsg "fork() failed: $!\n"; } } sleep 1; } sub child { my $job = shift; my $dbh = DBI->connect(); # Child connecting # .. do the job .. $dbh->disconnect(); exit; }
What handle am I trying to share? Why is the parent $dbh not destroyed before the child process tries to connect?DBD::mysql::dr connect failed: handle 1 is owned by thread 183f3e8 not + current thread 260eb64 (handles can't be shared between threads and +your driver may need a CLONE method added) at C:/PERL/site/lib/DBI.pm + line 598. DBD::mysql::dr disconnect_all failed: handle 1 is owned by thread 183f +3e8 not current thread 260eb64 (handles can't be shared between threa +ds and your driver may need a CLONE method added) at C:/PERL/site/lib +/DBI.pm line 677. END failed--call queue aborted.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI and fork() on Win32
by Corion (Patriarch) on Feb 10, 2009 at 13:55 UTC | |
by FloydATC (Deacon) on Feb 10, 2009 at 14:43 UTC | |
by Corion (Patriarch) on Feb 10, 2009 at 14:53 UTC | |
by FloydATC (Deacon) on Feb 10, 2009 at 15:22 UTC | |
by Corion (Patriarch) on Feb 10, 2009 at 15:46 UTC | |
| |
|
Re: DBI and fork() on Win32
by Anonymous Monk on Feb 10, 2009 at 15:59 UTC | |
|
Re: DBI and fork() on Win32
by Illuminatus (Curate) on Feb 10, 2009 at 14:54 UTC | |
by BrowserUk (Patriarch) on Feb 10, 2009 at 15:02 UTC | |
by ikegami (Patriarch) on Feb 10, 2009 at 15:48 UTC |