对不起老问题.我澄清了.如何用我糟糕的线程类启动一个停止线程?
编辑:它在循环中,我想在代码的开头再次重新启动它.如何进行start-stop-restart-stop-restart?
我的课:
import threading
class Concur(threading.Thread):
def __init__(self):
self.stopped = False
threading.Thread.__init__(self)
def run(self):
i = 0
while not self.stopped:
time.sleep(1)
i = i + 1
Run Code Online (Sandbox Code Playgroud)
在主代码中,我想要:
inst = Concur()
while conditon:
inst.start()
#after some operation
inst.stop()
#some other operation
Run Code Online (Sandbox Code Playgroud)