【发布时间】:2012-04-20 00:58:24
【问题描述】:
我使用 NppExec/Notepad++ 运行 Python 脚本,并在运行时不断刷新我的输出缓冲区以使用 print 语句更新我的控制台窗口(默认缓冲输出仅在脚本完成执行)。
This 链接显示您需要做的就是使用命令python -u 来获得无缓冲的输出。对我的所有我的 Python 脚本使用这种执行模式是否有缺点,无论使用的编辑器是什么?我不清楚缓冲输出和非缓冲输出之间的区别。
编辑:我包含了这个小的 Python 计时器脚本作为示例:
#!usr/bin/env python
import time
import threading
import sys
class Timer(threading.Thread):
def __init__(self, seconds):
self.runTime = seconds
threading.Thread.__init__(self)
def run(self):
counter = self.runTime
for sec in range(self.runTime):
print counter
time.sleep(1.0)
counter -= 1
print "Done."
if __name__ == '__main__':
t = Timer(10)
t.start()
在这种情况下,缓冲输出和非缓冲输出在效率方面有何不同?
【问题讨论】:
标签: python notepad++ nppexec unbuffered-output