Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Should I call waitpid when using Parallel::ForkManager to fork in an infinite loop?

by ikegami (Patriarch)
on Aug 16, 2009 at 08:58 UTC ( [id://788992]=note: print w/replies, xml ) Need Help??


in reply to Should I call waitpid when using Parallel::ForkManager to fork in an infinite loop?

That's not a problem. start reaps children as well. Consider the following example:

my $max_children = 5; my $pm = Parallel::ForkManager->new($max_children); for my $i (0..9) { $pm->start and next; #... $pm->finish; } $pm->wait_all_children;
  • The 6th start will reap a child.
  • The 7th start will reap a child.
  • The 8th start will reap a child.
  • The 9th start will reap a child.
  • The 10th start will reap a child.
  • wait_all_children will reap the remaining 5 children.

With your infinite loop, it's no different. You'll be reaping child every time you create one (once you've created $max_children children).

It's a bug to use waitpid in a run_on_finish handler since the process has already been reaped by then.

  • Comment on Re: Should I call waitpid when using Parallel::ForkManager to fork in an infinite loop?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Should I call waitpid when using Parallel::ForkManager to fork in an infinite loop?
by BioLion (Curate) on Aug 16, 2009 at 12:04 UTC

    Is that true? I thought that $pm->finish did the reap, and allowed the manager to start another process (assuming that $max_procs processes have been started already)?

    So the OPs code would maintain $max_procs children at all time (because of the while (1) ), and as you said, no explicit cleanup or reaping need be added, because of the wonderfulness of Parallel::ForkManager!

    Just a something something...

      I thought that $pm->finish did the reap

      finish is only executed in the child. It can't do any reaping.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://788992]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found