Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Although this code doesn't do much, it tends to hang at the second fork (forking for ftp spider) I'm not aware of any limitation of grandchild forking... My only guess right now is that the grandchild DBI in ftpspider is conflicting with the child DBI in spider somehow... (BTW, DBI is also needed in the parent). Anyone have any similar experiences with using multi-generational DBI's? FWIW, I've also tried moving one of the forks to the ftpspider function. I've also tried making a dbi handle in the spider function and passing it to the ftpspider after it forks. No luck either way. As far as error messages go, I've been getting the following:sub spider { my $pid=fork(); if ($pid) { print "Parent.. returning\n"; return; } use DBI; my $sdbh = DBI->connect( "DBI:mysql:dbase;", 'username','password' ) or die "Couldn't connect to database: " . DBI->errstr; print "spider post-fork\n"; my $string = "SELECT data FROM info WHERE name='spiders'"; my $sth = $sdbh->prepare($string); #$sth->{InactiveDestroy}=1; $sth->execute; my $data = $sth->fetchrow_arrayref(); my $p=$data->[0]; print "spider says P is $p\n"; for (my $i=1;$i<10;$i++) { print "forking for ftpspider\n"; $pid=fork(); if (!$pid) { print "child... calling ftpspider\n"; ftpspider($i); } print "parent... finishing loop\n"; $|++; } print "finishing up db connections\n"; $sth->finish; $sdbh->disconnect; } sub ftpspider { my $call=shift; $|++; print "ftpspider called with $call... we're the grandchild\n"; use DBI; print "DBI used ok\n"; my $gdbh = DBI->connect( "DBI:mysql:dbase;", 'username','password' ) or die "Couldn't connect to database: " . DBI->errstr; print "gdbh created ok\n"; $gdbh->do("UPDATE info SET data=data+1 WHERE name='spiders'"); print "updated ok\n"; print "done updating grandchild... disconnecting\n"; $gdbh->disconnect; print "grandchild done.... exiting\n"; exit; }
help :]dbih_clearcom (h 0x3659508, com 0x571e828): FLAGS 0x111: COMSET Warn PrintError TYPE 2 PARENT DBI::dr=HASH(0x3659538) KIDS 1 (1 Active) IMP_DATA HASH(0x3659448) in 'DBD::mysql::db' Attempt to free non-existent shared string during global destruction.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI and fork()
by Juerd (Abbot) on Sep 27, 2002 at 22:32 UTC | |
by Anonymous Monk on Sep 27, 2002 at 22:51 UTC | |
by Anonymous Monk on Sep 27, 2002 at 23:17 UTC |