I am looking for debug pointers.
The code launches two processes: Process (1) a background process, and process(2) is GDB, the gdb target talks to the background process via a socket, I am creating an automated sw test environment, I need to control, interact and capture output (stdout) from the processes.
I'm using IPC::Open3() to create both processes processes, like this:
To process the stdout, I create a reader thread like this:# i,o,e are std in/out/err $p = open3( $i, $o, $e, @cmdline ); $hr->{'alive'} = 1; $hr->{'pid'} = $p; $hr->{'stdout'}= $o; $hr->{'stdin'} = $i; $hr->{'stderr'} = $e;
The above works quite well when I run one sub process. It locks up (the create call does not return) if I have two sub processes.# The reader is given the hash reference, the 'o' # indicates this is the 'stdout' reader $hr->{'o_thread'} = threads->create( \&reader_thread, $hr, 'o' );
My only means to Debug is via print() - tells me that the call to threads->create() does not return, and print statement I put before threads->create() occurs, the after does not. And the print statement I put at the entry to the reader_thread never happens,
To be clear, this works a few times then does not work again.
Any suggestions how to dig deeper and figure out what I am doing wrong. Often, I insert print statements into various PM modules, but - threads are not perl, they are native code.
The reader thread is quite simple:
sub reader_thread { my ($hr,$who) = @_; my $c; my $h; my $r; my $q; threads->detach(); # determine handle. if( $who eq 'o' ){ $h = $hr->{'stdout'}; } else { $h = $hr->{'stderr'}; } # Get the output queue $q = $hr->{'Q'}; while( 1 ){ if( $hr->{'alive'} == 0 ){ last; } # Try to read *ONE* byte $r = read( $h, $c, 1 ); if( $r > 0 ){ if( length($c) ){ $q->enqueue($c); } } else { threads->yield(); } } }
In reply to threads->create hangs by duane_ellis2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |