import threading class MyThread(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.stopthread = threading.Event() def run(self): for f in xrange(0,5): print "Hello from the thread" def stop(self): self.stopthread.set() mythread = MyThread() mythread.start() for f in xrange(0,4): print "hello from the outside" #-------------------------------------------------- # //mythread.stop() #--------------------------------------------------