1、运行时加-u参数,如 # python3 -u test.py >> test.log &

用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.readline()” inside a “while 1:” loop.

强制stdin,stdout和stderr完全不缓冲。

2、在不要缓冲的每一次print后面添加sys.stdout.flush()函数

3、脚本头部添加-u,如#!/usr/local/bin/python -u,道理同方法1

4、添加环境变量 PYTHONUNBUFFERED=1

最新文章

  1. CMD安装/删除服务
  2. user initialization list vs constructor assignment
  3. 如何使用Chrome Timeline 工具(译)
  4. CSS隐藏元素的几种方法
  5. Find them, Catch them
  6. UVa 10250 The Other Two Trees
  7. 从 Page not found: / 提示说起,我是怎么发现webstrom与myeclipse冲突问题及解决的
  8. 在VSTO界面中,调用xll中的函数
  9. Android Studio 调试过程中快捷查看断点处变量值(Ctrl+Shift+I无效)?
  10. Python中关于XML-RPC原理
  11. mysql_view
  12. .1-Vue源码起步
  13. 用python爬整本小说写入txt文件
  14. python matplotlib 播放图片变化过程
  15. Python 的 urllib.parse 库解析 URL
  16. html5-progress和meter用法
  17. [JSP] Action Tags
  18. Apache按天截断日志工具,无法生成访问日志
  19. N! (大数,优化)
  20. 解决redis-cli command not found问题

热门文章

  1. flask 设置访问地址 和 访问端口
  2. How to receive JSON as an MVC 5 action method parameter
  3. Guided Hacking DLL Injector 3.3
  4. JVM 自定义类加载器
  5. 脸型分类-Face shape classification using Inception v3
  6. JS构造函数中有return
  7. gitlab 构建常见错误
  8. c代码审查软件
  9. python清理docker-harbor的多余镜像
  10. idea-debug启动会卡住不动,BeanPostProcessors (for example: not eligible for auto-proxying),报错解决