Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use warnings; use feature 'say'; use MCE::Map; MCE::Map-> init( chunk_size => 1, max_workers => 4, user_begin => sub { print "## ", MCE-> wid, " started\n"; }, user_end => sub { print "## ", MCE-> wid, " completed\n"; }, ); my @a = MCE::Map-> run( sub { $_ }, [ 0 .. 9 ]); print "\n", "@a", "\n"; say $MCE::VERSION;
This, of course, prints:
## 1 started ## 3 started ## 2 started ## 4 started ## 1 completed ## 3 completed ## 2 completed ## 4 completed 0 1 2 3 4 5 6 7 8 9 1.882
I want to make dependency on MCE, in my module, very optional i.e. triggered by rare circumstances only. Replacing "use" with "require" results in just first 4 lines of output and process running indefinitely, 4 cores fully loaded.
MCE::Map being just a convenience, I can do this instead:
use strict; use warnings; use feature 'say'; require MCE; my @in = ( 0 .. 9 ); my @out; my $mce = MCE-> new( chunk_size => 1, max_workers => 4, user_begin => sub { print "## ", MCE-> wid, " started\n"; }, user_end => sub { print "## ", MCE-> wid, " completed\n"; }, user_func => sub { MCE-> gather( $_ )}, input_data => \@in, gather => \@out, ); $mce-> run; say "@out"; $mce-> shutdown;
And it runs perfectly. I understand I'll have to deal now with ordering of the output, it's not an issue. But that's the reason I was hoping to use MCE::Map to make it easier. Is this a bug?
In general, is very optional (documented) dependency on something big and complex as MCE a bad-bad-bad idea? I guess I'll have to indicate minimum required MCE version then, which for example above would be... 1.500?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Can't require MCE::Map (Strawberry)?
by Discipulus (Canon) on Mar 07, 2025 at 09:18 UTC | |
by Anonymous Monk on Mar 07, 2025 at 10:29 UTC | |
by etj (Priest) on Mar 08, 2025 at 15:43 UTC | |
Re: Can't require MCE::Map (Strawberry)?
by marioroy (Prior) on Mar 26, 2025 at 21:51 UTC | |
Re: Can't require MCE::Map (Strawberry)?
by marioroy (Prior) on Mar 26, 2025 at 20:27 UTC |