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.
In reply to DBI and fork() on Win32 by FloydATC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |