python - Disable output buffering -
is output buffering enabled default in python's interpreter sys.stdout
?
if answer positive, ways disable it?
suggestions far:
- use
-u
command line switch - wrap
sys.stdout
in object flushes after every write - set
pythonunbuffered
env var sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
is there other way set global flag in sys
/sys.stdout
programmatically during execution?
from magnus lycka answer on mailing list:
you can skip buffering whole python process using "python -u" (or#!/usr/bin/env python -u etc) or setting environment variable pythonunbuffered.
you replace sys.stdout other stream wrapper flush after every call.
class unbuffered(object): def __init__(self, stream): self.stream = stream def write(self, data): self.stream.write(data) self.stream.flush() def writelines(self, datas): self.stream.writelines(datas) self.stream.flush() def __getattr__(self, attr): return getattr(self.stream, attr) import sys sys.stdout = unbuffered(sys.stdout) print 'hello'
Comments
Post a Comment