in reply to Deadlock occurring, reason unknown

As tilly and toma pointed out, error checks might be useful; to quote approximately from Camel, 2nd edition:

"""
Always check the return values of system calls.
Always check the return values of system calls.
ALWAYS CHECK THE RETURN VALUES OF SYSTEM CALLS!
"""

Which I of course forgot to do. Oops. Will add error checks and reply again if I still can't figure out the problem.

Update: Well, that didn't seem to be the problem, because I added checks, and a wait (marked by ##):

$water = { map { my $process = $_; my @inputs = @ {$processes{$process}[1]}; $_, { prerequisites => [ @inputs ], oo_output => sub { my ($data) = shift; my ($pid, @fh, $active); @fh = map { $data->get($_) } @inputs; push @fh, \*STDIN if ((defined $start) and $start eq $ +process); $active = scalar @fh; local (*IN, *OUT, $/, $\); $/ = 1; $\ = ''; open2 \*OUT, \*IN, $processes{$process}[0] or die "Can't open2 \"${\($processes{$process}[0])}\": $!, $? +, $^E; stopped"; ## select(IN) or die "Can't select IN: $!, $?, $^E; stopped"; ## for (;;) { my $piece = join '', map { my $x; (eof $_) ? "\0" : (defin +ed ($x = <$_>) ? $x : ( die "Can't read: ", ## "$!, $?, $^E; stopped" )) } @fh; (grep { not eof $_ } @fh) ? (print($piece) or die "Can't print: $!, $?, $^E; stopped") # +# : (last); } close (IN) or die "Can't close IN: $!, $?, $^E; stopped"; ## return \*OUT; } } } keys %processes }; tie %river, 'Data::Flow', $water; $SIG{CHLD} = sub { wait }; ## { my $output = $river{$final}; local $/ = undef; local $_; defined($_ = <$output>) or die "Can't read: $!, $?, $^E; stopped"; + ## print or die "Can't print: $!, $?, $^E; stopped"; ## } exit 0;
... and it no longer hangs at first, but then the pipes break, spilling data everywhere, and it hangs:
C:\premchai21\perl>perl multipipe.pl -f pipes
-p destination: Broken pipe
-p destination: Broken pipe
#kill.#
#darn!  killed emacs instead#
#kill!#
C:\premchai21\perl>
Tried it with a smaller set, "tiny", listed:
process cat perl -spew
start cat
final cat
Prompt transcript (read STDIN ok, ##s are what I type but don't see):
C:\premchai21\perl>perl multipipe.pl -f tiny
hello, world!
#^Z, RET#
#^Z, RET#
#^Z^Z^Z^Z^Z^Z^Z^Z^Z#
 at multipipe.pl line 102.

C:\premchai21\perl>
Line 102 is the line with the defined test on the read from $output, third from the end. So something seems to be wrong with the read, but as the die didn't function properly, I still can't tell exactly what's wrong. Was hoping for a more informative error message, which I didn't get.

Anyone?

Replies are listed 'Best First'.
Re: Re: Deadlock occurring, reason unknown
by premchai21 (Curate) on Jul 12, 2001 at 05:56 UTC
    Bleh. Forgot to reselect STDOUT before the final print. So, added select(STDOUT); right before the print line. Then:
    C:\premchai21\perl>perl multipipe.pl -f tiny
    hello, world!
    #^Z, RET#
    #^Z, RET#
    #^Z^Z^Z^Z^Z^Z^Z^Z^Z#
    
    Can't read: Bad file descriptor, 36081, ; stopped at multipipe.pl line 102.
    
    C:\premchai21\perl>
    
    So, from the error message, it seems as if I have a bad file descriptor. I can't imagine why, though. I think... I think I will add some debugging statements and try again.