如何使用我的简陋线程类启动和停止线程?
它处于循环状态,我想在代码开头重新启动它。如何实现启动-停止-重新启动-停止-重新启动?
我的类:
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
在主要的代码中,我想要:inst = Concur()
while conditon:
inst.start()
# After some operation
inst.stop()
# Some other operation