1. 程式人生 > 其它 >拼拼湊湊的python:Thread多執行緒

拼拼湊湊的python:Thread多執行緒

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。