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?

#!/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; } }
Results:
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.