python使用线程锁

#coding=utf8

import threading
import time
import thread


def echo(s):
    global lock
    with lock:
        for i in range(10):
            print s
            time.sleep(2)


if __name__=='__main__':
    lock = threading.Lock()
    thread.start_new_thread(echo, ('foo',) )
    thread.start_new_thread(echo, ('bar',) )
    while True:
        time.sleep(5)

你可能感兴趣的:(python使用线程锁)