Source

woocode / py / progress_bar_3.py

Full commit
# -*- encoding:utf-8 -*-

import thread
import time
import sys

def work():
    time.sleep(5)

def locked_call(func, lock):
    lock.acquire()
    func()
    lock.release()

# 分配一个锁
lock = thread.allocate_lock()
thread.start_new_thread(locked_call, (work, lock))

while (not lock.locked()):
    time.sleep(0.1)

while (lock.locked()):
    sys.stdout.write("*")
    sys.stdout.flush()
    time.sleep(1)

print "\nWork Done"