import threading
import time
def func(times,name):
for i in range(times):
print(name+' run: ' +str(i) +'\n')
time.sleep(1)
if __name__=='__main__':
thread_pool=[]
ret={}
th_1=threading.Thread(target=func,args=[5,'th_1'],name='th_1')
th_2=threading.Thread(target=func,args=[5,'th_2'],name='th_2')
thread_pool.append(th_1)
thread_pool.append(th_2)
print('主线程开始')
for th in thread_pool:
th.start()
for th in thread_pool:
th.join()
print('主线程结束')
import threading
class ThreadChild(threading.Thread):
def __init__(self,times,name):
threading.Thread.__init__(self)
self.times=times
self.name=name
def run(self):
for i in range(self.times):
print