2013-08-27 4 views
0

나는 기본적으로 효과를 사용하여 멀티 스레딩 그러나 도전이 때문이다 "로딩 바"를 만들려고 해요 멀티 스레드 정말 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  

답변

1

저는 curses이 작업을 수행 할 것이라고 생각합니다. 이것으로 가능한 것을보세요 example