Beispiel #1
0
 def testTimerException(self):
     count = 0
     with self.assertRaises(Timeout):
         with CountdownTimer(duration=timedelta(seconds=1)):
             while count < 3:
                 time.sleep(1)
                 count += 1
Beispiel #2
0
 def testNoTimer(self):
     no_timer = True
     try:
         with CountdownTimer(duration=None):
             time.sleep(1)
     except Timeout:
         no_timer = False
     self.assertTrue(no_timer)
Beispiel #3
0
 def testTimerNoException(self):
     no_timeout = True
     try:
         with CountdownTimer(duration=timedelta(seconds=3)):
             time.sleep(1)
     except Timeout:
         no_timeout = False
     self.assertTrue(no_timeout)
Beispiel #4
0
    def _exec(self):
        exc = None
        try:
            with CountdownTimer(duration=self.__timeout):
                self.check_and_clean()
        except Timeout as e:
            self.logger.error("Cleaner timeout.")
            exc = e
        except Exception as e:
            self.logger.error("Unexpected error to run cleaner.")
            exc = e

        if exc is not None:
            self.logger.exception(exc)
Beispiel #5
0
    def _exec(self):
        exc = None
        method_name = self.method.__name__
        try:
            self.logger.info("start to execute method %s.", method_name)
            with CountdownTimer(duration=self.timeout):
                self.method(self.arg)
        except Timeout as e:
            self.logger.error("command %s timeout.", method_name)
            exc = e
        except Exception as e:
            self.logger.error("unexpected error to run method %s.", method_name)
            exc = e

        if exc is not None:
            self.logger.exception(exc)
Beispiel #6
0
 def testTimerExceptionSleep(self):
     with self.assertRaises(Timeout):
         with CountdownTimer(duration=timedelta(seconds=1)):
             time.sleep(10)