class MyThreadSound(threading.Thread):
def __init__(self):
super(MyThreadSound, self).__init__()
self.isexit = False
self.ispause = True
self.pausetimeout = None # 暫停等待最大超時60S self.pausetimeout =None 表示無限等待
self.stopevent = threading.Event()
"""
暫停
"""
def pause(self):
self.ispause = True
"""
退出
"""
def exit(self):
self.isexit = True
self.wake()
"""
喚醒
"""
def wake(self):
self.ispause = False
self.stopevent.set()
def run(self):
while not self.isexit:
"""
在此做邏輯處理
"""
time.sleep(0.5)
if self.ispause:
self.stopevent.clear()
self.stopevent.wait(self.pausetimeout)