from threading import Thread
import time
class get_cookie(Thread):
def __init__(self):
Thread.__init__(self)
self._stop = False
def stop(self):
self._stop = True
def run(self):
while not self._stop:
print("-----------------------------------------cookie refreshed--------------------------------------------")
time.sleep(2)
qwe = get_cookie()
qwe.start()
time.sleep(3)
qwe.stop()
在python3.8可以定义自己的self._stop变量,来控制线程开关。python3.6中不能使用_stop,似乎是模块内用到了这个关键字,所以要换成_别的名字比如_stop1。