我想知道如何在Python(2.7.x)中同时运行进度条和其他任务,然后在任务完成时停止进度条。
import sys, time
def progress_bar():
while True:
for c in ['-','\\','|','/']:
sys.stdout.write('\r' + "Working " + c)
sys.stdout.flush()
time.sleep(0.2)
def work():
*doing hard work*
我该如何实现类似以下功能:
progress_bar() #run in background?
work()
*stop progress bar*
print "\nThe work is done!"