看大衛Beazley的(http://www.dabeaz.com)video about python threads,我是想出來的東西與線程與蟒蛇線程嘗試,如何停止線程
def countdown(n):
while n > 0:
if not n % 100000:
print n
n -= 1
>> from threading import Thread
>> t1=Thread(target=countdown,args=(10000000,))
>> t1.start();t1.join()
>>Ctrl-C
這給
>>10000000
9900000
9800000
9700000
9600000
Ctrl-C9500000
9400000
...
400000
300000
200000
100000
----------
KeyboardInterrupt :
...
現在我試圖找到狀態的線程
>>t1.isAlive()
>>False
所以,我試圖再次運行線程,whi ch造成了錯誤
>>t1.start();t1.join()
--------------
RuntimeError: thread already started
爲什麼會發生這種情況?有沒有辦法阻止線程?
你殺了進程你想如何運行它Ctrl-C發送信號來殺死正在運行的進程。 – 0x90