import sys,time
from threading import Thread
class worker(Thread):
def run(self):
for x in xrange(0,111):
print x
time.sleep(1)
def run():
worker().start()
if __name__ == '__main__':
run()
每秒打印一次
我直接用python text.py 执行 没问题 每秒输出一个数
但我在后台执行:
import sys,time
from threading import Thread
class worker(Thread):
def run(self):
for x in xrange(0,111):
print x
sys.stdout.flush()
time.sleep(1)
def run():
worker().start()
if __name__ == '__main__':
run()