我很难弄清楚为什么程序无限期地暂停,即显示出类似无限循环的行为
def class foo():
'''
...
'''
def __catcher(self, signum, _):
print "TIME OUT EXCEEDED"
# Reset timer
signal.setitimer(signal.ITIMER_REAL, 0.0, _SENDERTMOUT_)
# Do something
for i in range (self.base, self.next_seqno):
'''
...
'''
def start(self):
while something:
'''
Start doing some work
'''
if self.base == self.next_seqno:
old_handler = signal.signal(signal.SIGALRM, self.__catcher)
signal.setitimer(signal.ITIMER_REAL, _SENDERTMOUT_)
'''
Do more work until timer goes off
'''
也许我不知道执行的顺序,当定时器超时在start()中,程序跳转到__catcher(),对吗?然后计时器被重置,剩下的语句,然后程序在哪里恢复执行?
谢谢你的帮助!
我猜它会回到计时器中断的地方?