Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the MCE CPAN distribution.

Report information
The Basics
Id: 107925
Status: resolved
Priority: 0/
Queue: MCE

People
Owner: Nobody in particular
Requestors: rissenaj [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Reg. use of REGEXP items in MCE
Date: Thu, 22 Oct 2015 16:26:02 +0000
To: bug-MCE [...] rt.cpan.org
From: Rissen Joseph <rissenaj [...] gmail.com>
Hi Mario, I need to do a regex matching of a list of regular expressions passed inside an MCE flow task. I am encountering the following error Can't store REGEXP items at C:/Perl64/lib/Storable.pm line 340, <__ANONIO__> line 2, at C:/Perl64/site/lib/MCE/Queue.pm line 863. Looks like an issue when trying to serialize a REGEXP using Storable. Could you please let me know if there is a workaround. Thanks Rissen
Subject: Re: [rt.cpan.org #107925] Reg. use of REGEXP items in MCE
Date: Thu, 22 Oct 2015 12:31:54 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
Hello Rissen, Can you provide a small script so that I can reproduce the issue. MCE 1.7 will be released soon and want to include the fix if feasible. Thanks. Kind regards, Mario
Subject: Re: [rt.cpan.org #107925] Reg. use of REGEXP items in MCE
Date: Thu, 22 Oct 2015 17:13:22 +0000
To: bug-MCE [...] rt.cpan.org
From: Rissen Joseph <rissenaj [...] gmail.com>
Hi Mario, Please find below a sample code for find with the issue. # START use warnings; use Time::HiRes 'sleep'; use MCE; use MCE::Flow; use MCE::Queue; use Data::Dumper; use File::Basename; sub gatherDataClosure { my $gatherRef = $_[0]; return sub { my ($key, $value) = @_; push (@{ $gatherRef->{FoundFiles}->{$key} }, $value); return; } } sub find { my ($args) = @_; my @dirsToSearch = @_; # Queues my $dirQueue; my $srchQueue; my $sharedResrcMutex; my @regexesToMatch; my %results; @regexesToMatch = defined($args->{regexData}) ? ((ref($args->{regexData}) eq "ARRAY") ? @{ $args->{regexData} } : ( $args->{regexData} )) : (); if(!scalar(@dirsToSearch)) { print "\nfind: Atleast one directory need to be specified for search\n"; exit 1; } if (!scalar(@regexesToMatch)) { print "\nfind: Regex data is mandatory\n"; exit 1; } use constant { MAX_PRODUCERS => 7, MAX_CONSUMERS => 8, }; $dirQueue = MCE::Queue->new(queue => \@dirsToSearch); $srchQueue = MCE::Queue->new(fast => 1); MCE::Flow::init { task_end => sub { my ($mce, $task_id, $task_name) = @_; $srchQueue->enqueue((undef) x MAX_CONSUMERS) if $task_name eq 'prod'; }, gather => gatherDataClosure(\%results) }; ## Override any MCE options and run. Notice how max_workers and ## task_name take an anonymous array to configure both tasks. mce_flow { max_workers => [ MAX_PRODUCERS, MAX_CONSUMERS ], task_name => [ 'prod', 'cons' ], }, sub { ## Prod Task. Allow time for wid 1 to enqueue any dir entries. ## Otherwise, workers (wid 2+) may terminate early. sleep 0.1 if MCE->task_wid > 1; while (defined (my $dir = $dirQueue->dequeue_nb)) { my (@files, @dirs); foreach (glob("$dir/*")) { if (-d $_) { push @dirs, $_; next; } push @files, $_; } if (scalar @dirs) { $dirQueue->enqueue(@dirs); $srchQueue->enqueue(@dirs); } $srchQueue->enqueue(@files) if scalar @files; } }, sub { ## Cons Task. while (defined (my $node = $srchQueue->dequeue)) { foreach (@regexesToMatch) { MCE->gather($_, $node) if ($node =~ qr/$_/i); } } }; ## Workers persist in models. This may be ommitted. It will run ## automatically during exiting if not already called. MCE::Flow::finish; return %results; } my $regex = qr/[a-zA-Z0-9]+\.txt$/; my %srchResults = find({regexData => $regex}, "C:/temp"); print Dumper(\%srchResults); #END Thanks Rissen On Thu, Oct 22, 2015 at 9:32 AM Mario Roy via RT <bug-MCE@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=107925 > > > Hello Rissen, > > Can you provide a small script so that I can reproduce the issue. MCE 1.7 > will be released soon and want to include the fix if feasible. > > Thanks. > > Kind regards, > Mario > >
Subject: Re: [rt.cpan.org #107925] Reg. use of REGEXP items in MCE
Date: Thu, 22 Oct 2015 14:15:10 -0400
To: bug-MCE [...] rt.cpan.org
From: Mario Roy <marioeroy [...] gmail.com>
Hello Rissen, Should that be a shift, not @_ for $args? sub find { my ($args) = shift; my @dirsToSearch = @_; print "## args : $args\n"; print "## dirsToSearch : @dirsToSearch\n"; ... } The issue is still there as far as Storable not serializing REGEXP. But, the script runs and complains during gathering only. Perhaps, have a lookup hash with your regex patterns and gather the key or string value, not $_ (Regexp). foreach (@regexesToMatch) { MCE->gather($_, $node) if ($node =~ qr/$_/i); } I tried freezing a Regexp reference and Storable complains. Unfortunately, am not able to work around this. use strict; use warnings; use Storable qw( freeze ); my $regex = qr/[a-zA-Z0-9]+\.txt$/; print ref($regex), "\n"; my $regex_frozen = freeze($regex); -- Output Regexp Can't store REGEXP items at /usr/lib64/perl5/vendor_perl/Storable.pm line 340, at test.pl line 11. Regards, Mario
Subject: Re: [rt.cpan.org #107925] Reg. use of REGEXP items in MCE
Date: Thu, 22 Oct 2015 18:48:18 +0000
To: bug-MCE [...] rt.cpan.org
From: Rissen Joseph <rissenaj [...] gmail.com>
Hi Mario, Oops, yeah, that needs to be shift!. Thanks for your quick reply. I will try using a lookup hash instead for gather. Thanks Rissen On Thu, Oct 22, 2015 at 11:16 AM Mario Roy via RT <bug-MCE@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=107925 > > > Hello Rissen, > > Should that be a shift, not @_ for $args? > > sub find > { > my ($args) = shift; > my @dirsToSearch = @_; > > print "## args : $args\n"; > print "## dirsToSearch : @dirsToSearch\n"; > > ... > } > > The issue is still there as far as Storable not serializing REGEXP. But, > the script runs and complains during gathering only. Perhaps, have a lookup > hash with your regex patterns and gather the key or string value, not $_ > (Regexp). > > foreach (@regexesToMatch) > { > MCE->gather($_, $node) if ($node =~ qr/$_/i); > } > > > I tried freezing a Regexp reference and Storable complains. Unfortunately, > am not able to work around this. > > use strict; > use warnings; > > use Storable qw( freeze ); > > my $regex = qr/[a-zA-Z0-9]+\.txt$/; > > print ref($regex), "\n"; > > my $regex_frozen = freeze($regex); > > > -- Output > > Regexp > Can't store REGEXP items at /usr/lib64/perl5/vendor_perl/Storable.pm line > 340, at test.pl line 11. > > Regards, > Mario > >
Subject: Re: [rt.cpan.org #107925] Reg. use of REGEXP items in MCE
Date: Thu, 22 Oct 2015 19:02:10 +0000
To: bug-MCE [...] rt.cpan.org
From: Rissen Joseph <rissenaj [...] gmail.com>
I'm new to MCE, with all the different models made available as part of the distribution, it was really easy to start coding right away. Great examples!. Thanks Rissen On Thu, Oct 22, 2015 at 11:48 AM Rissen Joseph <rissenaj@gmail.com> wrote: Show quoted text
> Hi Mario, > > Oops, yeah, that needs to be shift!. Thanks for your quick reply. I > will try using a lookup hash instead for gather. > > Thanks > Rissen > > On Thu, Oct 22, 2015 at 11:16 AM Mario Roy via RT <bug-MCE@rt.cpan.org> > wrote: >
>> <URL: https://rt.cpan.org/Ticket/Display.html?id=107925 > >> >> Hello Rissen, >> >> Should that be a shift, not @_ for $args? >> >> sub find >> { >> my ($args) = shift; >> my @dirsToSearch = @_; >> >> print "## args : $args\n"; >> print "## dirsToSearch : @dirsToSearch\n"; >> >> ... >> } >> >> The issue is still there as far as Storable not serializing REGEXP. But, >> the script runs and complains during gathering only. Perhaps, have a >> lookup >> hash with your regex patterns and gather the key or string value, not $_ >> (Regexp). >> >> foreach (@regexesToMatch) >> { >> MCE->gather($_, $node) if ($node =~ qr/$_/i); >> } >> >> >> I tried freezing a Regexp reference and Storable complains. Unfortunately, >> am not able to work around this. >> >> use strict; >> use warnings; >> >> use Storable qw( freeze ); >> >> my $regex = qr/[a-zA-Z0-9]+\.txt$/; >> >> print ref($regex), "\n"; >> >> my $regex_frozen = freeze($regex); >> >> >> -- Output >> >> Regexp >> Can't store REGEXP items at /usr/lib64/perl5/vendor_perl/Storable.pm line >> 340, at test.pl line 11. >> >> Regards, >> Mario >> >>
Marking this as resolved as the limitation is with the Storable module, not MCE. Thank you, Mario