比较靠谱的多线程实现

# -*- coding: utf-8 -*-

import time
import threading

class mio(threading.Thread):
    def __init__(self, name):
        threading.Thread.__init__(self)
        self.thread_name = name
        self.thread_stop = False

    def run(self):
        while not self.thread_stop:
            print(self.thread_name+'running!')
            time.sleep(2)

    def stop(self):
        print(self.thread_name+' stop')
        self.thread_stop = True


thread1 = mio('thread 1')
thread2 = mio('thread 2')
thread1.start()
thread2.start()
time.sleep(10)
thread1.stop()
time.sleep(10)
thread2.stop()