[Python-bugs-list] [ python-Feature Requests-764188 ] setvbuf for File object

SourceForge.net noreply@sourceforge.net
Tue, 29 Jul 2003 13:09:21 -0700


Feature Requests item #764188, was opened at 2003-07-01 15:21
Message generated for change (Comment added) made by jbrouwers
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=764188&group_id=5470

Category: Python Library
Group: None
Status: Closed
Resolution: Works For Me
Priority: 5
Submitted By: Yue Luo (yueluo)
Assigned to: Nobody/Anonymous (nobody)
Summary: setvbuf for File object

Initial Comment:
I wonder if it is possible to add a new method setvbuf to 
File object.  The method does the same as the setvbuf() 
in stdio.h.



----------------------------------------------------------------------

Comment By: Jean M. Brouwers (jbrouwers)
Date: 2003-07-29 15:09

Message:
Logged In: YES 
user_id=832557

Well yes, but -u may not work everywhere either.  Depends on
the platform and some other conditions, like Tkinter.  Check the
Python source code for all details.

Lastly, I have used '#!/.../python -u' as the first line in
Python
scripts and on RedHat Linux 8 it does work for my specific
needs.


----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2003-07-29 14:43

Message:
Logged In: YES 
user_id=21627

yueluo: In short, there is no way to change the buffering of
stdout except by using -u. Since you seem to be happy with
that approach, I'm closing this issue.

----------------------------------------------------------------------

Comment By: Jean M. Brouwers (jbrouwers)
Date: 2003-07-29 13:15

Message:
Logged In: YES 
user_id=832557

Here's the best answer I can provide.  Quoting from the
O'Reilly book "Python in a Nutshell", page 188: "On some
platforms, you can change the buffering for files already
open, but there is no cross-platform way to do this".

If Python file objects were enhanced with a new method, say
bufsize(), to change the buffering of an open file, that
method may not work for all file types or may not work on
all platforms.  That is probably OK, since there is nothing
else Python could do and such platform specific behavior is
not uncommon in Python.

Btw, it is very common for stderr to be non-buffered and
stdout to be buffered, by default.  That may create an
additional problems, for example output to stderr may show
up before output stdout sent earlier.  One way to avoid that
is to flush stdout often.  Another is, redirect stdout and
stderr to a single pipe.



----------------------------------------------------------------------

Comment By: Yue Luo (yueluo)
Date: 2003-07-29 12:04

Message:
Logged In: YES 
user_id=806666

The -u command line option is not what I had in mind, but it
will achieve exactly what I wanted.  I just did not know
that it exists.  Maybe this request can be closed.
  
Can I use the optional bufsize to file(), open(), to change
the buffer mode of the standard output?  The stdout and
stderr are already opened.


----------------------------------------------------------------------

Comment By: Jean M. Brouwers (jbrouwers)
Date: 2003-07-28 19:27

Message:
Logged In: YES 
user_id=832557

There is already an optional bufsize argument to file(),
open() and fdopen().  It allows you to specify unbuffered
(0), line buffered (1), system default (-1) or buffered
usage with a specific buffer size (>1).  Are you requesting
something different?

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2003-07-08 01:57

Message:
Logged In: YES 
user_id=21627

I see. Can you explain why invoking "python -u" is insufficient?

----------------------------------------------------------------------

Comment By: Yue Luo (yueluo)
Date: 2003-07-07 18:14

Message:
Logged In: YES 
user_id=806666

Sorry, I did not make myself clear.  I just want to be able to 
change the buffer size or the buffer mode of a file object. 
Especially, I often want to change the standard output buffer 
mode to line buffer so that I can see the result immediately 
even when the output has been redirected.

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2003-07-07 17:08

Message:
Logged In: YES 
user_id=21627

What buf argument would you like to pass?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=764188&group_id=5470