-----Original Message-----
>From: Chas Owens <[EMAIL PROTECTED]>
>Sent: May 10, 2007 12:02 AM
>To: Jeff Pang <[EMAIL PROTECTED]>
>Cc: beginners-list <[email protected]>
>Subject: Re: forking problem with dbd::mysql
>
>On 5/9/07, Jeff Pang <[EMAIL PROTECTED]> wrote:
>snip
>> But still has a question for me.We may see this similiar destroy method on
>> DBI class,
>>
>> sub DESTROY
>> {
>> my $self = shift;
>> my $dbh = $self->{'dbh'};
>> if ($dbh) {
>> local $SIG{'__WARN__'} = sub {};
>> $dbh->disconnect();
>> }
>> }
>>
>> Ok where in child when going out of scope the $dbh should get disconnected.
>> But why this would affect the $dbh in parent?As we know,when forking child
>> get a
>> full copy of $dbh from parent and it's separate to parent's $dbh.
>snip
>
>But the connection information in the $dbh is the same, so when the
>child disconnects it tells the MySQL server to destroy the connection.
> This means that the parent loses its connection unexpectedly.
Yes but I think is this maybe a bug in DBI class?For example,open a file handle
and after forking child close that handle,this would not affect parent's handle.
The codes below show the case,
use strict;
use warnings;
open HDW,">","test.txt" or die;
select HDW;$|++;select STDOUT;
my $pid = fork;
die "can't fork" unless defined $pid;
unless ($pid) {
for (1..10) {
print HDW "child $_\n";
sleep 1;
}
exit 0;
} else {
for (1..100) {
print HDW "parent $_\n";
sleep 1;
}
}
__END__
parent would continue to write till end at 100.
--
mailto:[EMAIL PROTECTED]
http://home.arcor.de/jeffpang/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/