def test_timeout_exception_handler(self): s3_client = MagicMock() ExceptionHandler(s3_client).handle_exception(TimeoutException(), "SomeRoute", "SomeToken") s3_client.respond_back_with_error.assert_called_once_with(S3_STATUS_CODES.BAD_REQUEST_400, S3_ERROR_CODES.RequestTimeout, "Failed to complete document processing within time limit", "SomeRoute", "SomeToken")
def retry(self, first_request_time, retry_count): elapsed = datetime.now() - first_request_time if elapsed.total_seconds() > self._retry_timeout: raise TimeoutException() # inverse qps * (1.5 ^ i) is an increased sleep time of 1.5x per # iteration. delay = (1.0 / self._queries_per_second) * 1.5**retry_count # https://www.awsarchitectureblog.com/2015/03/backoff.html # https://github.com/googlemaps/google-maps-services-python/blob/master/googlemaps/client.py#L193 sleep_time = delay * (random.random() + 0.5) time.sleep(sleep_time)
def until_not(self, method, message=''): """Calls the method provided with the driver as an argument until the \ return value is False.""" end_time = time.time() + self._timeout while (True): try: value = method(self._driver) if not value: return value except self._ignored_exceptions: return True time.sleep(self._poll) if (time.time() > end_time): break raise TimeoutException(message)
def execute_task_with_timeout(timeout_in_millis, task): """ Execute a given task within a given time limit. :param timeout_in_millis: milliseconds to timeout :param task: task to execute :raise: TimeoutException """ timeout_in_sec = int(timeout_in_millis / 1000) try: executor = concurrent.futures.ThreadPoolExecutor(max_workers=1) future_result = executor.submit(task) return future_result.result(timeout=timeout_in_sec) except TimeoutError: # Free up the resources executor.shutdown(wait=False) raise TimeoutException()
def run_submission_with_timeout(self, mission, timeout, parameters): ''' Runs a child mission, throwing an exception if more time than specified in timeout passes before the mission finishes executing. ''' submission = self.run_submission(mission, parameters) if timeout == 0: # Timeout of zero means no timeout result = yield submission defer.returnValue(result) timeout_df = self.nh.sleep(timeout) result, index = yield defer.DeferredList([submission, timeout_df], fireOnOneCallback=True, fireOnOneErrback=True) if index == 0: yield timeout_df.cancel() defer.returnValue(result) if index == 1: yield submission.cancel() raise TimeoutException(timeout)
def _wait(self): while (not self.is_open() or self.force_lock): time.sleep(.1) self.count += 1 if self.count > self.wait_interval: raise TimeoutException('Timeout')
def handle_timeout(self, signum, frame): raise TimeoutException('Execution timeout')