📜  python 如何重启线程 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:52.653000             🧑  作者: Mango

代码示例1
# You can not restart a thread in python
# However you can make sure it stays alive forever
# If threads ending is a problem just loop them forever

# Example:
import threading
import time

class mythreader(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.running = True
        self.start()
        
    def run(self):
        mycounter = 0
        while self.running:
            do_some_cool_stuff()
            time.sleep(2)