in reply to Re^6: Useful number of childs revisited
in thread Useful number of childs revisited [SOLVED]
Do you mean that sleep $sleep_period should be replaced with select( '','','', $sleep_period )?
Yes. Because: sleep uses whole seconds; whereas select "The timeout, if specified, is in seconds, which may be fractional.... You can effect a sleep of 250 milliseconds this way:select( undef, undef, undef, 0.25 );".
That would allow you to avoid setting $pm->set_waitpid_blocking_sleep(0);; by instead setting set_waitpid_blocking_sleep( $seconds ); to a much lower -- but non-zero! -- value than the standard one whole second (say:0.01) which would also achieve the goal of avoiding the pregnant pause between one child process ending and its replacement being started.
The reason why this latter method is preferable to setting the timeout (sleep period) to 0; is documented in the "BLOCKING CALLS" section of the P::FM docs. It basically comes down to the fact that when the timeout is set to 0; instead of using wait to wait for particular child processes; it uses waitpid to wait for any child process. In most circumstances that will be fine because the only child processes will be those that were started by, and thus being managed by, P::FM.
But, if the parent process is also starting other child processes, then waitpid can also be woken by one of those other children that shouldn't be under P::FMs control; thus a) the code that started this 'other' child won't be able to obtain its return code; b) P::FM will start another child thinking that one of its child processes has ended, when it hasn't.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^8: Useful number of childs revisited
by karlgoethebier (Abbot) on May 09, 2015 at 12:39 UTC |