def testTimerException(self): count = 0 with self.assertRaises(Timeout): with CountdownTimer(duration=timedelta(seconds=1)): while count < 3: time.sleep(1) count += 1
def testNoTimer(self): no_timer = True try: with CountdownTimer(duration=None): time.sleep(1) except Timeout: no_timer = False self.assertTrue(no_timer)
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)
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)
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)
def testTimerExceptionSleep(self): with self.assertRaises(Timeout): with CountdownTimer(duration=timedelta(seconds=1)): time.sleep(10)