http://www.perlmonks.org?node_id=1020897


in reply to Re^5: Perl 5.8.8 threads, clean exit
in thread Perl 5.8.8 threads, clean exit

What I want to do is the following (in wierd prototype):

main: our %ssh (hash of active ssh sessions, Net::OpenSSH) read file with list of vm's to turn off. for each line with 1 or more vm's start thread1 kill_all_thread1 after timeout for each line with 1 or more vm's start thread2 thread1: @vms = split (',',$0) for each vm gather all info needed if (! exists $ssh{vm-manager} { $ssh{vm-manager} = Net::OpenSSH->new(vm-manager) (stdout,stderr)=$ssh{vm-manager}->capture2(request vm to stop) *check errors* (status,stderr)=$ssh{vm-manager}->capture2(request status vm) while (status != dead) { (status,stderr)=$ssh{vm-manager}->capture2(request status + vm) sleep some time } thread2: @vms = split (',',$0) for each vm gather all info needed if (! exists $ssh{vm-manager} { $ssh{vm-manager} = Net::OpenSSH->new(vm-manager) (stdout,stderr)=$ssh{vm-manager}->capture2(pull plug vm)

The current solution with ksh has several problems:

Now I'm typing this, I'm thinking of relocating the timeout inside the while loop of thread1, combine thread 1 and 2 and have the resulting thread handle the stopping of it's list. When a timeout within the thread occurs, kill and be friendly with the next. (or surrender after second timeout and exit with a list of vms that have not yet been disabled.)

With the scenario above, is it possible to have a second timeout in main and just simply exit when the main timeout is reached?

$_->join for @jobs;

This waits for the threads to end, how to escape this line? As far as I can find, that's where I need the signal (and the threads->exit() in the signal handler) for.

Replies are listed 'Best First'.
Re^7: Perl 5.8.8 threads, clean exit
by BrowserUk (Patriarch) on Feb 27, 2013 at 15:22 UTC

    Is there a question in there?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.