print buffer in Perl 5.10

Discussion in 'Perl Misc' started by John, Jun 3, 2009.

  1. John

    John Guest

    Hi

    Moved from Etch to Lenny in Debian and from Perl 5.8.8 to 5.10.

    Normally I use:
    our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
    socket hot
    but this appears no longer to work and output is now buffered.

    Any ideas?
    John
     
    John, Jun 3, 2009
    #1
    1. Advertising

  2. John

    John Guest

    "Ben Morrow" <> wrote in message
    news:...
    >
    > Quoth "John" <>:
    >>
    >> Moved from Etch to Lenny in Debian and from Perl 5.8.8 to 5.10.
    >>
    >> Normally I use:
    >> our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
    >> socket hot
    >> but this appears no longer to work and output is now buffered.

    >
    > That construction (ugly as it may be) ought to still work in 5.10.
    > Please post a complete, short script that we can run which demonstrates
    > your problem.
    >
    > Ben
    >


    The proram is embarrassingly small but I cannot stop the print buffer.

    #!/usr/bin/perl
    use strict;
    use warnings;

    # use FileHandle; STDOUT->autoflush(1);
    our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
    socket hot

    print "Content-type: text/html\n\n";

    print "hallo\n";
    print "hallo<br>\n";
    sleep(5);
    print "hallo<br>\n";
    sleep(5);
    print "hallo<br>";
    sleep(10);
    print "hallo<br>";
    sleep(2);

    Regards
    John
     
    John, Jun 4, 2009
    #2
    1. Advertising

  3. John

    Jim Gibson Guest

    In article <h0850t$q2j$>, John <>
    wrote:

    > "Ben Morrow" <> wrote in message
    > news:...
    > >
    > > Quoth "John" <>:
    > >>
    > >> Moved from Etch to Lenny in Debian and from Perl 5.8.8 to 5.10.
    > >>
    > >> Normally I use:
    > >> our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
    > >> socket hot
    > >> but this appears no longer to work and output is now buffered.

    > >
    > > That construction (ugly as it may be) ought to still work in 5.10.
    > > Please post a complete, short script that we can run which demonstrates
    > > your problem.
    > >
    > > Ben
    > >

    >
    > The proram is embarrassingly small but I cannot stop the print buffer.


    What do you mean by "stop the print buffer"?

    >
    > #!/usr/bin/perl
    > use strict;
    > use warnings;
    >
    > # use FileHandle; STDOUT->autoflush(1);
    > our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
    > socket hot
    >
    > print "Content-type: text/html\n\n";
    >
    > print "hallo\n";
    > print "hallo<br>\n";
    > sleep(5);
    > print "hallo<br>\n";
    > sleep(5);
    > print "hallo<br>";
    > sleep(10);
    > print "hallo<br>";
    > sleep(2);


    The program can be made even smaller and still demonstrate the
    condition (I hesitate to call it a "problem" as I do not know what the
    problem is.)

    #!/usr/local/bin/perl
    use strict;
    use warnings;
    our $old_fh=select(STDOUT); $|=1; select($old_fh); #line 4
    for my $n ( 1..5 ) {
    print "Line $n "; # line 6
    sleep(2);
    }
    print "\n";

    Note that if you replace line 6 with:
    print "Line $n\n";
    on my system (Mac OS 10.5.7, Perl 5.10.0), the newline character forces
    a flush regardless of the autoflush setting on STDOUT. You need to run
    the program as shown above with and without line 4 to see the
    difference.

    Your program looks like a CGI program. Are you trying to run it from a
    command-line or from a browser? That will certainly affect your
    expected results.

    Please explain in more detail the problem you are trying to solve.

    Thanks.

    --
    Jim Gibson
     
    Jim Gibson, Jun 4, 2009
    #3
  4. John

    John Guest

    "Jim Gibson" <> wrote in message
    news:040620090919280377%...
    > In article <h0850t$q2j$>, John <>
    > wrote:
    >
    >> "Ben Morrow" <> wrote in message
    >> news:...
    >> >
    >> > Quoth "John" <>:
    >> >>
    >> >> Moved from Etch to Lenny in Debian and from Perl 5.8.8 to 5.10.
    >> >>
    >> >> Normally I use:
    >> >> our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard
    >> >> output
    >> >> socket hot
    >> >> but this appears no longer to work and output is now buffered.
    >> >
    >> > That construction (ugly as it may be) ought to still work in 5.10.
    >> > Please post a complete, short script that we can run which demonstrates
    >> > your problem.
    >> >
    >> > Ben
    >> >

    >>
    >> The proram is embarrassingly small but I cannot stop the print buffer.

    >
    > What do you mean by "stop the print buffer"?
    >
    >>
    >> #!/usr/bin/perl
    >> use strict;
    >> use warnings;
    >>
    >> # use FileHandle; STDOUT->autoflush(1);
    >> our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
    >> socket hot
    >>
    >> print "Content-type: text/html\n\n";
    >>
    >> print "hallo\n";
    >> print "hallo<br>\n";
    >> sleep(5);
    >> print "hallo<br>\n";
    >> sleep(5);
    >> print "hallo<br>";
    >> sleep(10);
    >> print "hallo<br>";
    >> sleep(2);

    >
    > The program can be made even smaller and still demonstrate the
    > condition (I hesitate to call it a "problem" as I do not know what the
    > problem is.)
    >
    > #!/usr/local/bin/perl
    > use strict;
    > use warnings;
    > our $old_fh=select(STDOUT); $|=1; select($old_fh); #line 4
    > for my $n ( 1..5 ) {
    > print "Line $n "; # line 6
    > sleep(2);
    > }
    > print "\n";
    >
    > Note that if you replace line 6 with:
    > print "Line $n\n";
    > on my system (Mac OS 10.5.7, Perl 5.10.0), the newline character forces
    > a flush regardless of the autoflush setting on STDOUT. You need to run
    > the program as shown above with and without line 4 to see the
    > difference.
    >
    > Your program looks like a CGI program. Are you trying to run it from a
    > command-line or from a browser? That will certainly affect your
    > expected results.
    >
    > Please explain in more detail the problem you are trying to solve.
    >
    > Thanks.
    >
    > --
    > Jim Gibson


    Yes it is run from a browser.

    Since autoflush has been set then each line should be printed immediately
    followed by a wait of so many seconds.

    At present, all the output is buffered and then printed at one go.

    At the weekend we upgraded the server from Debian Etch to Debian Lenny, and
    from Perl 5.8.8 to Perl 5.10.

    Previously the autoflush was working.

    Regards
    John
     
    John, Jun 4, 2009
    #4
  5. John

    Jim Gibson Guest

    In article <h08sjh$rgb$>, John <>
    wrote:

    > "Jim Gibson" <> wrote in message
    > news:040620090919280377%...
    > > In article <h0850t$q2j$>, John <>
    > > wrote:
    > >


    > > #!/usr/local/bin/perl
    > > use strict;
    > > use warnings;
    > > our $old_fh=select(STDOUT); $|=1; select($old_fh); #line 4
    > > for my $n ( 1..5 ) {
    > > print "Line $n "; # line 6
    > > sleep(2);
    > > }
    > > print "\n";
    > >
    > > Note that if you replace line 6 with:
    > > print "Line $n\n";
    > > on my system (Mac OS 10.5.7, Perl 5.10.0), the newline character forces
    > > a flush regardless of the autoflush setting on STDOUT. You need to run
    > > the program as shown above with and without line 4 to see the
    > > difference.
    > >
    > > Your program looks like a CGI program. Are you trying to run it from a
    > > command-line or from a browser? That will certainly affect your
    > > expected results.


    > Yes it is run from a browser.
    >
    > Since autoflush has been set then each line should be printed immediately
    > followed by a wait of so many seconds.
    >
    > At present, all the output is buffered and then printed at one go.
    >
    > At the weekend we upgraded the server from Debian Etch to Debian Lenny, and
    > from Perl 5.8.8 to Perl 5.10.
    >
    > Previously the autoflush was working.


    You can run the program included above from a command line to test
    whether your Perl installation performs autoflushing correctly.
    Hopefully, it does.

    It is more likely that your web server or browser has changed behavior.
    Autoflushing Perl's STDOUT means that partial lines will get to the web
    server promptly. It doesn't mean that the web server will send the
    lines to the browser promptly, or that the browser will display those
    lines promptly in a browser window. Unfortunately, I don't think Perl
    is going to be able to help you with this problem without a major
    re-implementation. See, for example, the article:

    <http://www.stonehenge.com/merlyn/LinuxMag/col39.html>

    --
    Jim Gibson
     
    Jim Gibson, Jun 4, 2009
    #5
  6. On 2009-06-04 09:44, John <> wrote:
    >
    > "Ben Morrow" <> wrote in message
    > news:...
    >>
    >> Quoth "John" <>:
    >>>
    >>> Moved from Etch to Lenny in Debian and from Perl 5.8.8 to 5.10.
    >>>
    >>> Normally I use:
    >>> our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard output
    >>> socket hot
    >>> but this appears no longer to work and output is now buffered.

    [...]
    > The proram is embarrassingly small but I cannot stop the print buffer.


    [program snipped]

    Your program works fine on Debian Lenny. To test, invoke it like this:

    $ ./john | cat

    It will wait after each "<br>".

    hp
     
    Peter J. Holzer, Jun 4, 2009
    #6
  7. John

    John Guest

    "Peter J. Holzer" <> wrote in message
    news:...
    > On 2009-06-04 09:44, John <> wrote:
    >>
    >> "Ben Morrow" <> wrote in message
    >> news:...
    >>>
    >>> Quoth "John" <>:
    >>>>
    >>>> Moved from Etch to Lenny in Debian and from Perl 5.8.8 to 5.10.
    >>>>
    >>>> Normally I use:
    >>>> our $old_fh=select(STDOUT); $|=1; select($old_fh); # Make standard
    >>>> output
    >>>> socket hot
    >>>> but this appears no longer to work and output is now buffered.

    > [...]
    >> The proram is embarrassingly small but I cannot stop the print buffer.

    >
    > [program snipped]
    >
    > Your program works fine on Debian Lenny. To test, invoke it like this:
    >
    > $ ./john | cat
    >
    > It will wait after each "<br>".
    >
    > hp
    >


    Thank you gentlemen

    OK, I have run it from the command line and it is fine. The program waits
    the required number of seconds and prints the next line.

    But it does not work on a browser (IE6 IE7 and FF).

    This probably (?) suggests Per 5.10 is OK and there is a setting in Apache2
    that is causing the output to buffer.

    Is that how you now see it?

    Regards
    John
     
    John, Jun 5, 2009
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raja
    Replies:
    12
    Views:
    24,528
    John Harrison
    Jun 21, 2004
  2. Replies:
    2
    Views:
    611
    sergejusz
    Mar 26, 2007
  3. keto
    Replies:
    0
    Views:
    998
  4. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    374
    David Cournapeau
    Dec 30, 2008
  5. Neal Becker

    buffer creates only read-only buffer?

    Neal Becker, Jan 8, 2009, in forum: Python
    Replies:
    0
    Views:
    419
    Neal Becker
    Jan 8, 2009
Loading...

Share This Page