threading_join_demo

 1 import  time, threading
 2 
 3 
 4 class MyThread(threading.Thread):
 5     def run(self):
 6         for i in range(30):
 7             print("thread:", i)
 8             time.sleep(0.1)
 9 
10 
11 if __name__ == '__main__':
12     th = MyThread()
13     th.start()
14     #  join([time]): 等待至线程中止。这阻塞调用线程直至线程的join() 方法被调用中止-正常退出或者抛出未处理的异常-或者是可选的超时发生。
15     th.join()
16     for i in range(10):
17         print('main:', i)
18         time.sleep(0.1)

 

posted on 2018-08-15 00:19  jovelove  阅读(101)  评论(0)    收藏  举报