Skip to content

Instantly share code, notes, and snippets.

@cloudhan
Last active March 24, 2020 06:41
Show Gist options
  • Save cloudhan/199e06d7da804ea92c932893205c3981 to your computer and use it in GitHub Desktop.
Save cloudhan/199e06d7da804ea92c932893205c3981 to your computer and use it in GitHub Desktop.
make stdout unbuffered
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)
sys.stderr = Unbuffered(sys.stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment