python print时延问题的解决办法
来源:互联网 发布:卖家开通淘宝客的条件 编辑:程序博客网 时间:2024/06/06 00:25
最近写了几个Python脚本,在用print输出的时候,都有一个很讨厌的问题,就是print的输出被延迟了,什么情况呢,类似这样
1 import os
2 print ‘first print
3 os.system('./second-print.sh')
在second-print.sh中,也会有一些打印信息输出到控制台
正常情况下,first print要先于second print出现再控制台,但实际的情况却是相反的。
这是个小问题,却非常的烦人,今天终于不能忍受,google了一番,发现很多人都有同样的痛苦,痛苦的根源是python默认启用了stdout缓冲,解决的办法有两种
一种办法是每次print后,都调用stdout flush(),把缓冲区打印出来,这个办法比较麻烦,要重载stdout,不推荐。
最简单的方法是用命令行参数-u启动python,禁用stdout缓冲
比如脚本是build-native.py,运行 python -u build-native.py就不会出现print延迟问题了
0 0
- python print时延问题的解决办法
- python print UUID的问题
- Python的print输出中文对齐问题
- Python的input(),print()函数问题
- python 的print输出
- Python的print函数
- Python的print用法
- python的print
- Python Print的扩展
- python的print 功能
- python的输出 print print, write
- 解决python print延迟问题
- python 关于print函数问题
- 关于Python中的 print 函数的缩进问题
- 解决Python的print中文在windows命令行乱码问题
- 【Python】3.x 版本的print 乱码 问题
- python学习笔记2:print的使用中的一些问题
- Python的print 格式化输出
- BZOJ2005 [Noi2010]能量采集
- 用xcode来debug以makefile组织的程序
- ios的ssh密码忘记的处理方法
- pat a1005(暂缺)
- JavaScript面向对象高级
- python print时延问题的解决办法
- 第三章 DispatcherServlet详解
- IOException parsing XML document from class path resource [springmvc-servlet.xml]; nested exception
- POJ 3986 Math teacher's homework 已被翻译
- 网络拥塞
- Javascript中event对象的clientX,LayerX,offsetX, pageX
- 我准备换博客了
- Qt之系统托盘(QSystemTrayIcon详解)
- 我的数据库