Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^4: Win32 capturing output from a process that may hang

by Random_Walk (Prior)
on Mar 02, 2005 at 18:54 UTC ( #435967=note: print w/replies, xml ) Need Help??

in reply to Re^3: Win32 capturing output from a process that may hang (Updated!)
in thread Win32 capturing output from a process that may hang

Hi BrowserUK

Well you can put your jaundiced view aside for a second here. Your code did not do exactly what I wanted (I caught the wait timeout even if code is done issue) but I have altered it and as far as my testing goes up to now I think I have exactly what I want. Here are the salient fragments

# this is a direct c&p from a larger opus of code # but you should get the idea. # command is worked out earlier depending on the # platform we are running on my $timeout=60; my @sqlo; my $Q = new Thread::Queue; threads->create( \&RunInThread, $command, $Q ); my $pid = $Q->dequeue; for (1..$timeout) { sleep 1; my $result=$Q->dequeue_nb; # non_block, return undef if nowt o +n queue next unless $result; # twas nowt on queue if ($result eq "$pid is done") { $trace->trace("SQL process finished within $_ seconds"); last; } push @sqlo, $result; } my $killed = kill 9, $pid if kill 0, $pid; # kill child if still +alive if ($killed) { $trace->trace("Had to kill SQL process, taking more than $time +out secs"); } sub RunInThread { my ( $cmd, $Q) = @_; my $pid = open CMD, "$cmd |" or $trace->die("$cmd : $!"); $Q->enqueue($pid); $Q->enqueue( $_ ) while defined( $_ = <CMD> ); $Q->enqueue("$pid is done"); }

The multithreading is also great as I may have several DBs to examine so a little refactoring and I can do them all in parallel improving the chance of completion within the 120 sec time limit no end.


Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^5: Win32 capturing output from a process that may hang (Updated!)
by BrowserUk (Pope) on Mar 02, 2005 at 19:58 UTC


    Sending the pid back to the parent thread and having it do the killing is very shrewd--and obvious. Now you've shown me:)

    Thanks for the feedback. I love to learn.

    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://435967]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (6)
As of 2016-10-28 02:32 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (374 votes). Check out past polls.