python2.7 kill thread and find thread id

Yang Chun-Kai waitmeforever at hotmail.com
Wed Jan 4 01:10:46 EST 2012


Hello,guys!!
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.
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.
Kay 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120104/eb27de79/attachment.html>


More information about the Python-list mailing list