in reply to Re: Parent waiting on child when using modules
in thread Parent waiting on child when using modules

Well I know I'm confused. Here is a test case that will show my problem. When this is run as a cgi script, the browser will wait until the child exits before finishing. If I comment out the two Spreadsheet modules it works perfectly and finishes without waiting on the child process.
use strict; go(); sub go { $| = 1; $SIG{CHLD} = 'IGNORE'; close STDIN; my $pid = fork; if (!defined($pid)) { print "Content-type: text/plain\n\n"; print "Could not fork!\n"; exit; } elsif ($pid) { print "Content-type: text/plain\n\n"; print "PARENT = $$, KID = $pid\n" . localtime(time); close STDERR; close STDOUT; close STDIN; exit; } else { close STDIN; close STDOUT; close STDERR; use Spreadsheet::ParseExcel; use Spreadsheet::WriteExcel; open(STDERR, ">test.err"); sleep(10); open(OUT,">>test") or die(); print OUT "\nKID(me) = $$ " . localtime(time); close OUT; exit; } }

Replies are listed 'Best First'.
Re^3: Parent waiting on child when using modules
by Keystroke (Scribe) on Dec 03, 2004 at 20:46 UTC
    I tracked the problem down
    Spreadsheet::WriteExcel uses
    Spreadsheet::WriteExcel::Workbook which uses
    Spreadsheet::WriteExcel::Worksheet which uses
    Spreadsheet::WriteExcel::Formula which uses
    Parse::RecDescent

    and confirmed that Parse::RecDecent duplicates STDERR to 3 filehandles.

    This fixes the problem I have.
    close Parse::RecDecent::ERROR;
    close Parse::RecDecent::TRACECONTEXT;
    close Parse::RecDecent::CONTEXT;

    Is there any way to track down open filehandles in perl?