develooper Front page | perl.perl5.porters | Postings from March 2019

[perl #133949] paragraph input mode ($/="") prevents readline fromreturning latest paragraph from pipe

Thread Previous
From:
James E Keenan via RT
Date:
March 24, 2019 00:43
Subject:
[perl #133949] paragraph input mode ($/="") prevents readline fromreturning latest paragraph from pipe
Message ID:
rt-4.0.24-30334-1553388210-668.133949-15-0@perl.org
On Fri, 22 Mar 2019 22:48:18 GMT, rob.navarro@appdynamics.com wrote:
> Subject: paragraph input mode ($/="") prevents readline from returning
> latest paragraph from pipe
> Message-Id: <5.10.1_6992_1553291784@centos67S>
> Reply-To: rob.navarro@appdynamics.com
> To: perlbug@perl.org
> 
> 
> This is a bug report for perl from rob.navarro@appdynamics.com,
> generated with the help of perlbug 1.39 running under perl 5.10.1.
> 
> 
> -----------------------------------------------------------------
> Noticed whilst trying to filter live and long-running "iostat -tmzx 3"
> in
> time sensitive application.
> 
> The very last "paragraph" written into a pipe is not found by readline
> until the next block of pipe inputs are emitted or EOF is sent.
> There are no issues when reading from a file.
> This is only a problem with readline in paragraph mode reading from a
> pipe
> i.e. perl -000 ... or perl -e '$/=""; ...'
> 
> [terminal output follows]
> # Firstly to prove I can read line buffered rows on right hand side of
> pipe
> i.e. reading when they are sent without delay:
> 
> $ perl -MPOSIX -e 'select((select( STDOUT ), $|=1)[0]);for (1..3) {
> print
> "## ".strftime( "%FT%T", localtime )." $_\n\n" for (1..3); sleep 5 }'|
> {
> while read -r L; do echo "$(date +%FT%T)>> $L"; done; }
> 2019-03-22T15:22:27>> ## 2019-03-22T15:22:27 1
> 2019-03-22T15:22:27>>
> 2019-03-22T15:22:27>> ## 2019-03-22T15:22:27 2
> 2019-03-22T15:22:27>>
> 2019-03-22T15:22:27>> ## 2019-03-22T15:22:27 3
> 2019-03-22T15:22:27>>
> 2019-03-22T15:22:32>> ## 2019-03-22T15:22:32 1
> 2019-03-22T15:22:32>>
> 2019-03-22T15:22:32>> ## 2019-03-22T15:22:32 2
> 2019-03-22T15:22:32>>
> 2019-03-22T15:22:32>> ## 2019-03-22T15:22:32 3
> 2019-03-22T15:22:32>>
> 2019-03-22T15:22:37>> ## 2019-03-22T15:22:37 1
> 2019-03-22T15:22:37>>
> 2019-03-22T15:22:37>> ## 2019-03-22T15:22:37 2
> 2019-03-22T15:22:37>>
> 2019-03-22T15:22:37>> ## 2019-03-22T15:22:37 3
> 2019-03-22T15:22:37>>
> 
> # Notice that in above the pipe reader's timestamp matches the
> timestamp
> sent through the pipe for each of the three "paragraphs".
> # Now with Perl reading from pipe with -000 or equally problematic
> with
> $/=""
> 
> $ perl -MPOSIX -e 'select((select( STDOUT ), $|=1)[0]);for (1..3) {
> print
> "## ".strftime( "%FT%T", localtime )." $_\n\n" for (1..3); sleep 5 }'
> |
> perl -MPOSIX -000 -e 'while (<>) { print "## ".strftime( "%FT%T",
> localtime
> )." ## >$_<"; }'
> ## 2019-03-22T15:22:44 ## >## 2019-03-22T15:22:44 1
> 
> <## 2019-03-22T15:22:44 ## >## 2019-03-22T15:22:44 2
> 
> <## 2019-03-22T15:22:50 ## >## 2019-03-22T15:22:44 3
> 
> <## 2019-03-22T15:22:50 ## >## 2019-03-22T15:22:50 1
> 
> <## 2019-03-22T15:22:50 ## >## 2019-03-22T15:22:50 2
> 
> <## 2019-03-22T15:22:55 ## >## 2019-03-22T15:22:50 3
> 
> <## 2019-03-22T15:22:55 ## >## 2019-03-22T15:22:55 1
> 
> <## 2019-03-22T15:22:55 ## >## 2019-03-22T15:22:55 2
> 
> <## 2019-03-22T15:23:00 ## >## 2019-03-22T15:22:55 3
> 
> # Notice that only two of the three paragraphs are output before 5
> second
> sleep. Pipe reader timestamp is always 5 seconds behind for third
> "paragraph".
> 
> [end of terminal output]
> 
> This issue seems to occur regardless of how big or small each
> paragraph is
> and seems to be just related to the last paragraph not being found by
> readline.
> There is no problem with $/="\n" or sysread from a pipe, only a
> problem
> when paragraph mode for readline() has been enabled i.e. -000 or
> $/="";
> 
> Also a problem on v5.18.2
> 
> 

Confirmed in perl-5.28.0.

-- 
James E Keenan (jkeenan@cpan.org)

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=133949

Thread Previous


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