[perl #131764] Passing stdin to Proc::Async mostly does not work ($proc.print: …; $proc.close-stdin)

2017-09-18 Thread Aleks-Daniel Jakimenko-Aleksejev via RT
Closing this myself in favor of this ticket:
https://github.com/perl6/doc/issues/1567

On 2017-07-17 23:51:21, alex.jakime...@gmail.com wrote:
> Alright, it seems that rakudo is not entirely incorrect here. See this
> discussion: https://irclog.perlgeek.de/perl6-dev/2017-07-18#i_14885863
>
> TL;DR, one should use something like this:
>
> whenever $proc.print(“one\ntwo\nthree\nfour”) { $proc.close-stdin }
>
> So it seems that it's not a bug, but a trap maybe?
>
> I'll leave this for somebody else to close.
>
> On 2017-07-17 22:45:01, alex.jakime...@gmail.com wrote:
> > Code:
> >
> > sub get-output() {
> > my $proc = Proc::Async.new: :w, ‘head’, ‘-n’, ‘1’;
> > my $success;
> > react {
> > whenever $proc.stdout { $success = True }
> > whenever $proc.start { die ‘FAIL!’ unless $success }
> >
> > $proc.print: “one\ntwo\nthree\nfour”;
> > $proc.close-stdin;
> > }
> > say $++;
> > }
> >
> > loop { get-output }
> >
> >
> > Again, the result depends on your luck. Ideally it should not “die”
> > ever, because there should always be one line in the output and
> > therefore $success will be set to true. However, sometimes its stdout
> > is empty and therefore it fails. It may fail after 20+ executions, and
> > sometimes it fails almost immediately.
> >
> > Related ticket: https://rt.perl.org/Ticket/Display.html?id=131763



[perl #131764] Passing stdin to Proc::Async mostly does not work ($proc.print: …; $proc.close-stdin)

2017-07-18 Thread Aleks-Daniel Jakimenko-Aleksejev via RT
Alright, it seems that rakudo is not entirely incorrect here. See this
discussion: https://irclog.perlgeek.de/perl6-dev/2017-07-18#i_14885863

TL;DR, one should use something like this:

whenever $proc.print(“one\ntwo\nthree\nfour”) { $proc.close-stdin }

So it seems that it's not a bug, but a trap maybe?

I'll leave this for somebody else to close.

On 2017-07-17 22:45:01, alex.jakime...@gmail.com wrote:
> Code:
>
> sub get-output() {
> my $proc = Proc::Async.new: :w, ‘head’, ‘-n’, ‘1’;
> my $success;
> react {
> whenever $proc.stdout { $success = True }
> whenever $proc.start { die ‘FAIL!’ unless $success }
>
> $proc.print: “one\ntwo\nthree\nfour”;
> $proc.close-stdin;
> }
> say $++;
> }
>
> loop { get-output }
>
>
> Again, the result depends on your luck. Ideally it should not “die”
> ever, because there should always be one line in the output and
> therefore $success will be set to true. However, sometimes its stdout
> is empty and therefore it fails. It may fail after 20+ executions, and
> sometimes it fails almost immediately.
>
> Related ticket: https://rt.perl.org/Ticket/Display.html?id=131763



[perl #131764] Passing stdin to Proc::Async mostly does not work ($proc.print: …; $proc.close-stdin)

2017-07-18 Thread Stefan Seifert via RT
$proc.print is asynchronous while $proc.close-stdin is not. In some cases $proc 
simply does not get the input because we closed its stdin before printing 
anything.

If .close-stdin is meant to by synchronous, this needs a doc patch. Otherwise 
we'd probably need to await any outstanding write promises before performing 
the actual nqp::closefh.



[perl #131764] Passing stdin to Proc::Async mostly does not work ($proc.print: …; $proc.close-stdin)

2017-07-17 Thread via RT
# New Ticket Created by  Aleks-Daniel Jakimenko-Aleksejev 
# Please include the string:  [perl #131764]
# in the subject line of all future correspondence about this issue. 
# https://rt.perl.org/Ticket/Display.html?id=131764 >


Code:

sub get-output() {
my $proc = Proc::Async.new: :w, ‘head’, ‘-n’, ‘1’;
my $success;
react {
whenever $proc.stdout { $success = True }
whenever $proc.start  { die ‘FAIL!’ unless $success }

$proc.print: “one\ntwo\nthree\nfour”;
$proc.close-stdin;
}
say $++;
}

loop { get-output }


Again, the result depends on your luck. Ideally it should not “die” ever, 
because there should always be one line in the output and therefore $success 
will be set to true. However, sometimes its stdout is empty and therefore it 
fails. It may fail after 20+ executions, and sometimes  it fails almost 
immediately.

Related ticket: https://rt.perl.org/Ticket/Display.html?id=131763