1 python 创建多线程方法一(继承类)
import sys, os, struct
import threading
import time
class mthread(threading.Thread):
flag=1
def __init__(self):
threading.Thread.__init__(self)
def run(self) -> None:
print(threading.current_thread().getName())
while (self.flag):
time.sleep(1)
print("This is thread run test.")
def stop(self):
self.flag=0
mt=mthread()
def main():
count = 0
print("main exit.")
mt.start()
while (1):
time.sleep(1)
count = count + 1
if(count == 10):
mt.stop()
if(count == 12):
break
print("main exit.")
if __name__ == '__main__':
main()