[Python-Dev] Can't have unbuffered text I/O in Python 3.0?

Brett Cannon brett at python.org
Fri Dec 19 23:03:01 CET 2008

On Fri, Dec 19, 2008 at 13:43, Fabio Zadrozny <fabiofz at gmail.com> wrote:
> Hi,
> I'm currently having problems to get the output of Python 3.0 into the
> Eclipse console (integrating it into Pydev).
> The problem appears to be that stdout and stderr are not running
> unbuffered (even passing -u or trying to set PYTHONUNBUFFERED), and
> the content only appears to me when a flush() is done or when the
> process finishes.
> So, in the search of a solution, I found a suggestion from
> http://stackoverflow.com/questions/107705/python-output-buffering
> to use the following construct:
> sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
> But that gives the error below in Python 3.0:
>    sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
>  File "D:\bin\Python30\lib\os.py", line 659, in fdopen
>    return io.open(fd, *args, **kwargs)
>  File "D:\bin\Python30\lib\io.py", line 243, in open
>    raise ValueError("can't have unbuffered text I/O")
> ValueError: can't have unbuffered text I/O
> So, I'd like to know if there's some way I can make it run unbuffered
> (to get the output contents without having to flush() after each
> write).

Notice how the exception specifies test I/O cannot be unbuffered. This
restriction does not apply to bytes I/O. Simply open it as 'wb'
instead of 'w' and it works.


More information about the Python-Dev mailing list