Thanks for commenting, RMGir-I greatly appreciate the input.
After reading your comment, I felt a little more confident that a test would not bork my box. The test code is below, but the results seemed to indicate that it actually did work, surprisingly enough. (I get a list of numbers, the "Who's left?" message, then what appears to be those in the queue at the time of the alarm.) I'm not sure which parts I'm reading incorrectly in the module's code that make it appear that it shouldn't work, though. Can someone verify that they get the same/similar results?
Results:#!/usr/bin/perl -w use Parallel::ForkManager; use strict; use vars qw($pm); sub max_processes { 5; } sub max_seconds { ( ( ( ( ( 0 * 24 ) + 0 ) * 60 ) + 0 ) * 60 ) + 10; } # Time in seconds - 0d 0h 0m 10s $pm = new Parallel::ForkManager(&max_processes); $SIG{ALRM} = sub { die ("TimeOut"); }; eval { alarm( &max_seconds() ); foreach my $data (0..500) { my $pid = $pm->start and next; print($data); sleep(int(rand(10))); print('-', $data, "\n"); $pm->finish; } print("Waiting on everyone...\n"); $pm->wait_all_children; alarm(0); }; if ($@) { if ( $@ =~ m/TimeOut/ ) { # timed out; do what you will here $pm->set_max_procs(0); print("Who's left?\n"); $pm->wait_all_children; } else { alarm(0); die; } }
2-2 3-3 6-6 5-5 8-8 4-4 9-9 7-7 12-12 0-0 10-10 1-1 11-11 Who's left? 14-14 15-15 16-16 13-13 17-17
In reply to Re^2: Graceful shutdowns and Parallel::ForkManager
by atcroft
in thread Graceful shutdowns and Parallel::ForkManager
by atcroft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |