threading多线程,没有提供线程退出的方法。
如果在死循环多线程,则即使CTRL+C也没有任何效果:
例如:
#coding=utf8
import threading
import time
def showperson(name):
while True:
time.sleep(1)
print 'show person :%s'%name
print '%s thread start!'%(time.ctime())
list=[]
for i in range(3):
t =threading.Thread(target=showperson,args=("person-%d"%i,))
list.append(t)
t.start()
for threadinglist in list:
threadinglist.join()
print '%s thread end!'%(time.ctime())
输出:
[root@myrpc zrd]# python threadkill.py
Fri May 26 22:38:37 2017 thread start!
show person :person-0
show person :person-1
show person :person-2
^C^Cshow person :person-0
show person :person-1
show person :person-2
^C^C^C^Cshow person :person-0
show person :person-1
show person :person-2
^C^C^C^Cshow person :person-0
show person :person-1
show person