我基本上是尝试使用多线程创建“加载栏”效果但是挑战是由于(我至少假设) sys.stdout.flush 它确实没有产生我愿意做出的效果;
Starting .... Done!
Starting ....... Done! # Two of the has to work simultaneously
只是为了让一切都清楚,这是一个(应该是)截图,而程序正在运行;
Starting ..
Starting .
Starting ...
Starting ..
Starting .... Done!
Starting ...
我想知道它是否可能?这是我迄今为止尝试过的代码并没有解决;
import time
import sys
import thread
def do_task():
time.sleep(1)
def example_1(n, end_word):
for i in range(n):
do_task()
print '\b.',
sys.stdout.flush()
print end_word + '!'
def func_1():
print ''
sys.stdout.write('Starting ')
example_1(3, 'Done')
def func_2():
print ''
sys.stdout.write('Starting ')
example_1(4, 'Done')
thread.start_new_thread(func_1, ())
thread.start_new_thread(func_2, ())
while 1:
pass