develooper Front page | perl.perl6.compiler | Postings from June 2018

[perl #125908] [BUG] duplicate triggers of .act when using parallelgreps on an IO::Notification.watch_path supply

From:
Jan-Olof Hendig via RT
Date:
June 23, 2018 20:05
Subject:
[perl #125908] [BUG] duplicate triggers of .act when using parallelgreps on an IO::Notification.watch_path supply
Message ID:
rt-4.0.24-18976-1529784352-763.125908-80-0@perl.org
On Tue, 03 Nov 2015 08:54:16 -0800, root+bitcard@retupmoca.com wrote:
> 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




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About