如何在python中同时打印循环下方的字符串

如何在python中同时打印循环下方的字符串,python,Python,我想同时做多个过程, 例如,我想在正在进行的循环下面打印一些字符串 import time from threading import Thread print 'top' def foo(): for i in range(1,10): sys.stdout.write(str('\r%s\r'%i)) sys.stdout.flush() time.sleep(1) timer = Thread(target=foo) timer.start() '''bo

我想同时做多个过程, 例如,我想在正在进行的循环下面打印一些字符串

import time
from threading import Thread
print 'top'
def foo():   
  for i in range(1,10):
    sys.stdout.write(str('\r%s\r'%i))
    sys.stdout.flush()
    time.sleep(1)
timer = Thread(target=foo)
timer.start()
'''bottom'
我想上面的代码是这样的

top
'''looping counter is underway'''
bottom

听起来您想在工作线程完成之前阻止主线程。所以你想要


那么,请阅读您最喜欢的线程文档

您需要加入()线程

timer.join()

计数器循环时,“底部”仍然不会出现。我认为没有办法先打印“底部”,然后再返回打印工作线程输出,除非您使用类似于[curses]的包
timer.join()