Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
p6rt opened this issue Jul 18, 2017 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Jul 18, 2017

Migrated from rt.perl.org#131764 (status was 'resolved')

Searchable as RT131764$

@p6rt
Copy link
Author

p6rt commented Jul 18, 2017

From @AlexDaniel

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-archive.perl.org/perl6/Ticket/Display.html?id=131763

@p6rt
Copy link
Author

p6rt commented Jul 18, 2017

From @niner

$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.

@p6rt
Copy link
Author

p6rt commented Jul 18, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jul 18, 2017

From @AlexDaniel

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.jakimenko@​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-archive.perl.org/perl6/Ticket/Display.html?id=131763

@p6rt
Copy link
Author

p6rt commented Sep 18, 2017

From @AlexDaniel

Closing this myself in favor of this ticket​: Raku/doc#1567

On 2017-07-17 23​:51​:21, alex.jakimenko@​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.jakimenko@​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-archive.perl.org/perl6/Ticket/Display.html?id=131763

@p6rt
Copy link
Author

p6rt commented Sep 18, 2017

@AlexDaniel - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Sep 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant