Linux发球区不使用Python?

我做了一个python脚本,使用无限循环与Web服务器通信。 我想将每个通讯数据logging到一个文件中,并同时从terminal监控它们。 所以我用这样的tee命令。

python client.py | tee logfile 

然而,我从terminal和日志文件没有得到什么。 python脚本工作正常。 这里发生了什么? 我错过了什么?

一些build议将不胜感激。 先谢谢你。

man python

  -u Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout and stderr in binary mode. Note that there is internal buffering in xreadlines(), readlines() and file- object iterators ("for line in sys.stdin") which is not influenced by this option. To work around this, you will want to use "sys.stdin.read‐ line()" inside a "while 1:" loop. 

所以你可以做的是:

 /usr/bin/python -u client.py >> logfile 2>&1 

或者使用tee

 python -u client.py | tee logfile