kill/cancel a started thread

ellisjb at ellisjb at
Wed Aug 25 15:16:33 CEST 2004

You need to have your thread check for some condition that signals it
to exit.  E.g., stopnicely in the following class (subclass and provide
an action method to do something useful):

class StoppableThread(threading.Thread):
def __init__(self, **kwds):
threading.Thread.__init__(self, **kwds)
self.keepgoing = True

def stopnicely(self):
self.keepgoing = False

def run(self):
while self.keepgoing:
print "Thread " + self.getName() + " has stopped"


More information about the Python-list mailing list