Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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

by marioroy (Priest)
on Jun 15, 2018 at 13:00 UTC ( #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 (Novice) 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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2019-03-22 05:51 GMT
Find Nodes?
    Voting Booth?
    How do you Carpe diem?

    Results (110 votes). Check out past polls.