python2.7 kill thread and find thread id

Yang Chun-Kai waitmeforever at
Wed Jan 4 01:20:58 EST 2012

Sorry for the misarrangement of my code in list, it happens everytime.
I apologized.

From: waitmeforever at
To: python-list at
Subject: python2.7 kill thread and find thread id
Date: Wed, 4 Jan 2012 14:10:46 +0800

I am using python2.7 to write a simple thread program which print the current running thread id
and kill it with this id.
But I have some questions with this.
 /div>My code: -----------------------------------------------------from threading import Threadclass 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):           *** // how to do this with its own id, for example "exit(self.tid)" ?if __name__ == "__main__"     go = t()     go.start()     go.kill()-----------------------------------------------------First, I can't call get_ident(), seems not supported.
Second, how to kill the thread with its own id?
I know I can use SystemExit() to shut this down, but I want to kill the certain
thread not the whole program. Anyone know how to fix my code to achieve it?
Any tips welcomed.
Thank you in advance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list