Can't have unbuffered text I/O in Python 3.0?
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). Thanks, Fabio
On Fri, Dec 19, 2008 at 13:43, Fabio Zadrozny <fabiofz@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. -Brett
Brett Cannon wrote:
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.
s/test/text/ :) (For anyone else that is like me and skipped over the exception detail on first reading, thus becoming a little confused...) Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia ---------------------------------------------------------------
You're right, thanks (guess I'll use that option then). Now, is it a bug that Python 3.0 doesn't run unbuffered when specifying -u or PYTHONUNBUFFERED, or was this support dropped? Thanks, Fabio On Fri, Dec 19, 2008 at 8:03 PM, Brett Cannon <brett@python.org> wrote:
On Fri, Dec 19, 2008 at 13:43, Fabio Zadrozny <fabiofz@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.
-Brett
participants (3)
-
Brett Cannon -
Fabio Zadrozny -
Nick Coghlan