Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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.

Cheers,
R.

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

    Neat!++

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://435967]
help
Chatterbox?
[Corion]: ... that's not that great for quasi-disposable devices ;)
[Eily]: can't you just remote connect to the linux machine ?
[marto]: IIRC the hiemdal suite made life much easier on windows, and people on XDA developers put out released of windows only pages for adb that made it less of a pain
[marto]: Eily you can't remote connect the physical device via USB ;)
[Corion]: Eily: Sure, that's what I do, but some things you need to do on the Android device directly, like when navigating the bootloader :-)
[Eily]: marto you just need a longer cable :P
[Corion]: marto: Yeah, but I'm somewhat wary of installing random USB drivers downloaded from mega.nz , Google Drive or whatever, so Linux wins there due to there being no conflicts and me just having to edit one text file in the worst case, to add the USB vendor
[hippo]: Long USB cable FTW.
[Corion]: Eily: I've thought of that, but I don't like running long cables through the appartment because sooner or later I'll trip over it, pulling at least one device off its stand :)
[marto]: hmm, may have to patch CPAN::Meta to move from search.cpan to metacpan in the META.json/yml files

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2018-05-23 09:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?