启动线程–没有显示运行结果!!!
from threading import Thread,currentThread
from time import sleep
def fun_thread(sec, tname):
print("启动线程->", currentThread().getName(),".",currentThread().is_alive())
print("线程t}setName修改线程名称\n".format(currentThread().getName()))
print("setName修改线程名称")
currentThread().setName(tname)
sleep(sec)
print("线程结束".fomat(currentThread().getName()))
if __name__ == '__main__':
threads = [] #维护线程
for i in range(3):
t = Thread(target=fun_thread, \
name="thread-%d"%i,\
args=(3,"My"+str(i)+"Thread"))
threads.append(t)
t.start()
for t in threads:
t.join()