拼拼湊湊的python:Thread多執行緒
阿新 • • 發佈:2020-12-25
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。