Skip Menu |
Report information
Id: 125908
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: muraiki [at] pair.com
Cc:
AdminCc:

Severity: (no value)
Tag: Bug
Platform: (no value)
Patch Status: (no value)
VM: (no value)



From: Erik Ferguson <muraiki [...] pair.com>
To: rakudobug [...] perl.org
Subject: [BUG] duplicate triggers of .act when using parallel greps on an IO::Notification.watch_path supply
Date: Wed, 26 Aug 2015 11:19:22 -0400
Download (untitled) / with headers
text/plain 1.4k
When two greps are used in parallel on one supply produced by IO::Notification.watch_path, greps that match are triggered twice. Run the following code, then in the same directory `touch watchfile`. Note that I'm also using unique to filter things, as touching a file produces a number of FileChanged events.
Show quoted text
my $paths = IO::Notification.watch_path('.')\
    .grep(*.event.isa(FileChangeEvent::FileChanged))\
    .unique(:as(*.path), :expires(5))\
    .map(*.path);

my $watch = $paths.grep(* ~~ /watchfile/)\
    .act(-> $x {            
        say "got file change: " ~ $x.perl;
    });                            
                                   
my $never = $paths.grep(* ~~ /shouldneverexecute/)\
    .act(-> $x {
        say "should never execute: " ~ $x.perl;
    });
  
sleep;
Output:
Show quoted text
got file change: "watchfile"
got file change: "watchfile"
The expected output should be only a single line, not two. I also noticed that each additional grep I add to the supply yields an additional line of the same output.

I tried this with a plain supply and could not reproduce the problem:
Show quoted text
my $s = Supply.new();

my $watch = $s.grep(* ~~ /1/)\
    .act(-> $x {   
        say "got one";
    });   

my $never = $s.grep(* ~~ /shouldneverexecute/)\
    .act(-> $x {
        say "should never execute";
    });

$s.emit(1);
$s.emit(2);

sleep;
This outputs "got one" a single time, as expected.

Perl6 version info: 2015.07.1-161-gf7cfe9d built on MoarVM version 2015.07-57-gec051f5
Subject: Re: [perl #125908] AutoReply: [BUG] duplicate triggers of .act when using parallel greps on an IO::Notification.watch_path supply
Date: Mon, 2 Nov 2015 17:31:34 -0500
From: Erik Ferguson <muraiki [...] pair.com>
To: perl6-bugs-followup [...] perl.org
Download (untitled) / with headers
text/plain 345b
A better description for this bug, now that I have a better idea of what is going on, is "two acts on one supply cause each act to be evaluated twice". :) In Reactive Extensions with cold observables, I could see this occurring. But it isn't clear to me from the concurrency design document that this is intended to be the case in Perl 6.
Download (untitled) / with headers
text/plain 1.9k
On Wed Aug 26 08:19:35 2015, muraiki@pair.com wrote: Show quoted text
> When two greps are used in parallel on one supply produced by > IO::Notification.watch_path, greps that match are triggered twice. Run > the following code, then in the same directory `touch watchfile`. Note > that I'm also using unique to filter things, as touching a file produces > a number of FileChanged events. > > my $paths = IO::Notification.watch_path('.')\ > .grep(*.event.isa(FileChangeEvent::FileChanged))\ > .unique(:as(*.path), :expires(5))\ > .map(*.path); > > my $watch = $paths.grep(* ~~ /watchfile/)\ > .act(-> $x { > say "got file change: " ~ $x.perl; > }); > > my $never = $paths.grep(* ~~ /shouldneverexecute/)\ > .act(-> $x { > say "should never execute: " ~ $x.perl; > }); > > sleep; > > Output: > > got file change: "watchfile" > got file change: "watchfile" > > The expected output should be only a single line, not two. I also > noticed that each additional grep I add to the supply yields an > additional line of the same output. > > I tried this with a plain supply and could not reproduce the problem: > > my $s = Supply.new(); > > my $watch = $s.grep(* ~~ /1/)\ > .act(-> $x { > say "got one"; > }); > > my $never = $s.grep(* ~~ /shouldneverexecute/)\ > .act(-> $x { > say "should never execute"; > }); > > $s.emit(1); > $s.emit(2); > > sleep; > > This outputs "got one" a single time, as expected. > > Perl6 version info: 2015.07.1-161-gf7cfe9d built on MoarVM version > 2015.07-57-gec051f5
I think this is a bug in Supply.unique: 22:38 retupmoca m: my $s = Supply.new; my $s2 = $s.unique(:as({$_}), :expires(5)); $s2.act({say $_}); $s.emit(1); $s2.act({ say $_ * 2}); $s.emit(2); # re: #125908 22:38 camelia rakudo-moar 273e89: OUTPUT«1␤2␤4␤2␤4␤» 22:38 retupmoca looks like a bug in unique?
Download (untitled) / with headers
text/plain 2.8k
On Tue, 03 Nov 2015 08:54:16 -0800, root+bitcard@retupmoca.com wrote: Show quoted text
> On Wed Aug 26 08:19:35 2015, muraiki@pair.com wrote:
> > When two greps are used in parallel on one supply produced by > > IO::Notification.watch_path, greps that match are triggered twice. > > Run > > the following code, then in the same directory `touch watchfile`. > > Note > > that I'm also using unique to filter things, as touching a file > > produces > > a number of FileChanged events. > > > > my $paths = IO::Notification.watch_path('.')\ > > .grep(*.event.isa(FileChangeEvent::FileChanged))\ > > .unique(:as(*.path), :expires(5))\ > > .map(*.path); > > > > my $watch = $paths.grep(* ~~ /watchfile/)\ > > .act(-> $x { > > say "got file change: " ~ $x.perl; > > }); > > > > my $never = $paths.grep(* ~~ /shouldneverexecute/)\ > > .act(-> $x { > > say "should never execute: " ~ $x.perl; > > }); > > > > sleep; > > > > Output: > > > > got file change: "watchfile" > > got file change: "watchfile" > > > > The expected output should be only a single line, not two. I also > > noticed that each additional grep I add to the supply yields an > > additional line of the same output. > > > > I tried this with a plain supply and could not reproduce the problem: > > > > my $s = Supply.new(); > > > > my $watch = $s.grep(* ~~ /1/)\ > > .act(-> $x { > > say "got one"; > > }); > > > > my $never = $s.grep(* ~~ /shouldneverexecute/)\ > > .act(-> $x { > > say "should never execute"; > > }); > > > > $s.emit(1); > > $s.emit(2); > > > > sleep; > > > > This outputs "got one" a single time, as expected. > > > > Perl6 version info: 2015.07.1-161-gf7cfe9d built on MoarVM version > > 2015.07-57-gec051f5
> > I think this is a bug in Supply.unique: > > 22:38 retupmoca m: my $s = Supply.new; my $s2 = > $s.unique(:as({$_}), :expires(5)); $s2.act({say $_}); $s.emit(1); > $s2.act({ say $_ * 2}); $s.emit(2); # re: #125908 > 22:38 camelia rakudo-moar 273e89: OUTPUT«1␤2␤4␤2␤4␤» > 22:38 retupmoca looks like a bug in unique?
$ perl6 -v This is Rakudo version 2018.06-24-gc441d8d built on MoarVM version 2018.06 implementing Perl 6.c. tried the original code example and it now only produces one event, i.e. got file change: "watchfile" It was suspected that the real problem was a bug in Supply.unique, and the given example seems to confirm that. However, a lot of water have flowed under the bridges since then and it seems as if the problem in 'unique' has been fixed. I tried the following: perl6 -e 'my $x = Supplier.new; my $s = $x.Supply; my $s2 = $s.unique(:as({$_}), :expires(5)); $s2.act({say $_}); $x.emit(1); $s2.act({ say $_ * 2}); $x.emit(2);' 1 2 4 Had to rewrite the example since the api for supplies has changed since the original bug report. Should possibly be marked as TESTNEEDED


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org