#-------------------------------------------------------------------------------
class mythread(threading.Thread, Thread_Control):
'''
BaseThread Class With Control Method[stop, pause, restore]
time dilution of precision about 1 millisecond
thread state {-1:'STOP', 0:'READY', 1:'RUNNING', 2:'PAUSE'}
'''
def __init__(self, owner, ThreadName, TimeSpacing=0, TimeDelay = 0):
'''
__init__(self, owner, ThreadName, TimeSpacing=0)
owner The Thread Owner
ThreadName The Thread Name
TimeSpacing Run TimeSpacing
TimeDelay The Thread Start TimeDelay
'''
self.owner = owner
self.TimeSpacing = TimeSpacing #任务多长时间执行一次
self.TimeDelay = TimeDelay
Thread_Control.__init__(self)
threading.Thread.__init__(self, name = ThreadName)
self.setDaemon(1)
def run(self):
'''
This While loop stop until Terminated
This Object Has sotp, pause(timeout = None) and restore method
'''
if self.TimeDelay != 0:
TSTART = self.TimeDelay
else:
TSTART = 0
while 1:
try:
#这里是线程的停止处理
if self.Terminated:
break
#这里是线程的暂停处理
if self.TimeOut is not None:
#带有暂停超时的处理
self.ControlEvent.wait(self.TimeOut)
self.TimeOut = None
self.ControlEvent.set()
else:
#不带超时 那么必须等到线程恢复
self.ControlEvent.wait()