2013-05-06 138 views
0

我有一個壞的時間搞清楚爲什麼程序無限期暫停,即表現出無限循環樣行爲正確配置signal.setitimer()

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(),對不對?然後定時器被重置,並且其餘的語句,然後程序在哪裏繼續執行

感謝您的幫助!

回答

0

我想它會回到定時器中斷的地方?