Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Parallel::ForkManager dies with "Free to wrong pool..."

by marioroy (Prior)
on Jun 15, 2018 at 13:00 UTC ( [id://1216705]=note: print w/replies, xml ) Need Help??


in reply to Parallel::ForkManager dies with "Free to wrong pool..."

Greetings perlygapes,

Here is a version using MCE::Hobo. Workers may exit gracefully on Unix platforms to ease non-thread safe module(s) and possibly dependencies. Internally, MCE::Hobo sets the base generator uniquely between workers. Also for Math::Prime::Util and Math::Random.

#!/usr/bin/perl use 5.24.0; # Book, Chapter and Verse use strict; # the First Commandment use warnings; # the Second Commandment use Digest::MD5 qw(md5_hex); # identity and volition use Math::Prime::Util ':all'; # the Tempter # provides 'todigitstring' and 'fromdigits' use MCE::Hobo; # the Family Unit my @children = ("Cain","Abel","Seth","Noah","Shem"); my $children = 5; my $birthorder = 0; # Set max_workers to limit # of workers running simultaneously. # Set posix_exit to avoid all END and destructor processing # inside the worker (ignored on the Windows platform). MCE::Hobo->init( max_workers => $children, posix_exit => 1 ); the_main_reason(); sub the_main_reason { printf "Forming $children children.\n"; foreach my $child (@children) { $birthorder++; print "Today, I have begotten child $birthorder as $child\n"; MCE::Hobo->create("begotten_child", $child) } # my longsuffering print "Waiting on begotten childen...\n"; MCE::Hobo->waitall(); } # the_main_reason sub begotten_child { my ($child) = @_; if ($child =~ m/cain/i) { the_task_I_gave_cain_to_do("Cain"); } elsif ($child =~ m/abel/i) { the_task_I_gave_abel_to_do("Abel"); } elsif ($child =~ m/seth/i) { the_task_I_gave_seth_to_do("Seth"); } elsif ($child =~ m/noah/i) { the_task_I_gave_noah_to_do("Noah"); } elsif ($child =~ m/shem/i) { the_task_I_gave_shem_to_do("Shem"); } # enable some prayer print "Child $child exiting\n"; MCE::Hobo->exit(0); } # begotten_child exit; ...

Regards, Mario

Replies are listed 'Best First'.
Re^2: Parallel::ForkManager dies with "Free to wrong pool..."
by perlygapes (Sexton) on Jun 15, 2018 at 17:16 UTC
    Received with thanks, Mario.
    I will come back to commune with this if later I need to.
    My script is now working, but I note that this module uses POSIX exits.
    Whilst I do not yet understand what exactly the difference is, I am aware it behaves differently.
Re^2: Parallel::ForkManager dies with "Free to wrong pool..."
by perlygapes (Sexton) on Apr 25, 2020 at 03:38 UTC
    OK, coming back to this from my other question regarding PostgreSQL, I am running this on Windows and you mention that Windows ignores the POSIX exit.
    Can you tell me how this should change to run successfully on Windows?

    Thank you.

      Hi perlygapes,

      No changes needed on the Windows platform. The Hobo script in the prior post works. Append the script with the missing subroutines found here.

      sub the_task_I_gave_cain_to_do { ... } sub the_task_I_gave_abel_to_do { ... } sub the_task_I_gave_seth_to_do { ... } sub the_task_I_gave_noah_to_do { ... } sub the_task_I_gave_shem_to_do { ... }

      Output from Strawberry Perl 5.30.1:

      Forming 5 children. Today, I have begotten child 1 as Cain Today, I have begotten child 2 as Abel Cain is working. Today, I have begotten child 3 as Seth Abel is working. Today, I have begotten child 4 as Noah Seth is working. Today, I have begotten child 5 as Shem Noah is working. Waiting on begotten childen... Shem is working. Child Cain exiting

      Regards, Mario

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-16 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found