On Jun 21, 12:29 pm, Yang Zhang <[EMAIL PROTECTED]> wrote:
> Hi, is there any way to get unbuffered stdout/stderr without relying on
> the -u flag to python or calling .flush() on each print (including
> indirect hacks like replacing sys.stdout with a wrapper that succeeds
> each write() with a flush())?  Thanks in advance!
>

I think the only way is to reopen the stdout file descriptor:

import sys
import os

# reopen stdout file descriptor with write mode
# and 0 as the buffer size (unbuffered)
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

print "unbuffered text"

Sebastian
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to