import threading

classX(threading.Thread):
def__init__(self):
threading.Thread.__init__(self)
self.flag =1

defrun(self):
whileself.flag ==1:
sleep(300)
...

defrun(self):
self.last = time.time()
whileself.flag ==1:
Now = time.time()
ifNow - self.last >300:
self.last = Now
...

defrun(self):
self.last = time.time()
whileself.flag ==1:
sleep(1)
Now = time.time()
ifNow - self.last >300:
self.last = Now
...

import threading

classX(threading.Thread):
def__init__(self):
threading.Thread.__init__(self)
self.flag =1
self.cond = threading.Condition()

defrun(self):
self.cond.acquire()
self.condition.wait(300)
whileself.flag ==1:
...
self.cond.release()
self.cond.acquire()
self.condition.wait(300)

...
x.flag =0
x.cond.acquire()
x.cond.notify()
x.cond.release()

发表回复