美文网首页
python 多线程 join的用法

python 多线程 join的用法

作者: Do_More | 来源:发表于2017-07-15 15:33 被阅读0次
import threading
import time

def thread_job():
    print('T1 start\n')
    for i in range(10):
        time.sleep(0.1)
    print('T1 finish\n')

def T2_job():
    print('T2 start\n')
    print('T2 finish\n')

def main():
    added_thread = threading.Thread(target=thread_job, name="T1")
    thread2 = threading.Thread(target=T2_job, name='T2')
    added_thread.start()
    thread2.start()
    added_thread.join() 
    thread2.join()
    print('all done\n')

if __name__ == '__main__':
    main()

result:

T1 start

T2 start

T2 finish

T1 finish

all done

相关文章

网友评论

      本文标题:python 多线程 join的用法

      本文链接:https://www.haomeiwen.com/subject/zwtzhxtx.html