duane_ellis2 has asked for the wisdom of the Perl Monks concerning the following question:
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(); } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: threads->create hangs
by BrowserUk (Patriarch) on Aug 15, 2015 at 00:33 UTC | |
Re: threads->create hangs
by ikegami (Patriarch) on Aug 17, 2015 at 01:48 UTC | |
Re: threads->create hangs
by anonymized user 468275 (Curate) on Aug 16, 2015 at 00:12 UTC | |
by tye (Sage) on Aug 16, 2015 at 02:58 UTC | |
| |
Re: threads->create hangs
by anonymized user 468275 (Curate) on Aug 16, 2015 at 20:44 UTC | |
by ikegami (Patriarch) on Aug 17, 2015 at 01:42 UTC | |
by anonymized user 468275 (Curate) on Aug 17, 2015 at 09:08 UTC | |
by tye (Sage) on Aug 17, 2015 at 01:29 UTC | |
by anonymized user 468275 (Curate) on Aug 17, 2015 at 09:10 UTC | |
by Anonymous Monk on Aug 16, 2015 at 21:01 UTC | |
by SimonPratt (Friar) on Aug 17, 2015 at 12:01 UTC | |
by anonymized user 468275 (Curate) on Aug 17, 2015 at 14:53 UTC |