[問題] python2.7 thread 相關問題
使用python2.7寫一個簡單的thread程式,印出當前thread的id然後結束
code:
-----------------------------------------------------
from threading import Thread
class t(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
self.tid = Thread.get_ident()
print 'thread id is',self.tid
def kill(self):
請問這邊該怎麼寫? 譬如exit(self.tid)嗎
if __name__ == "__main__"
go = t()
go.start()
go.kill()
-----------------------------------------------------
但是一直沒辦法call get_ident() 好像不支援?
再者kill thread 能用指定id的方式殺掉嗎?
我知道可以使用SystemExit()不指定 但是這樣好像會全部都關掉
我希望可以指定thread id關閉
請問code該怎麼修正才正確呢?
謝謝~~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 118.167.25.215
→
01/04 13:11, , 1F
01/04 13:11, 1F
→
01/04 13:39, , 2F
01/04 13:39, 2F
→
01/04 22:38, , 3F
01/04 22:38, 3F
→
01/04 22:39, , 4F
01/04 22:39, 4F
推
01/05 00:10, , 5F
01/05 00:10, 5F
→
01/05 00:32, , 6F
01/05 00:32, 6F
→
01/05 00:33, , 7F
01/05 00:33, 7F
→
01/05 00:34, , 8F
01/05 00:34, 8F
→
01/05 00:35, , 9F
01/05 00:35, 9F
→
01/05 00:37, , 10F
01/05 00:37, 10F
→
01/05 00:38, , 11F
01/05 00:38, 11F
→
01/05 09:18, , 12F
01/05 09:18, 12F
→
01/05 09:20, , 13F
01/05 09:20, 13F
→
01/05 14:34, , 14F
01/05 14:34, 14F
Python 近期熱門文章
PTT數位生活區 即時熱門文章