Skip to content

Instantly share code, notes, and snippets.

@bao-qian
Last active November 15, 2017 19:04
Show Gist options
  • Select an option

  • Save bao-qian/3ebb323bd29299da6ff7c87324321e40 to your computer and use it in GitHub Desktop.

Select an option

Save bao-qian/3ebb323bd29299da6ff7c87324321e40 to your computer and use it in GitHub Desktop.
python tee example
from contextlib import contextmanager
from tee import StdoutTee, StderrTee
# λ python test.py
# test tee
# λ cat stdout.log
# test tee
@contextmanager
def Tee():
# must use buffer io on windows due to python 3.6 bug
with StdoutTee("stdout.log", buff=1), StderrTee("stderr.log", buff=1):
yield
def main():
with Tee():
print('test tee')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment