From 2eac5bcafb350ed2e56b24d73c1a1d7ff2141cca Mon Sep 17 00:00:00 2001 From: flaurent <florian.laurent@gmail.com> Date: Mon, 13 Jul 2020 17:35:13 +0200 Subject: [PATCH] Using custom exception for timeouts --- flatland/evaluators/client.py | 9 +++++++-- flatland/evaluators/service.py | 26 +------------------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/flatland/evaluators/client.py b/flatland/evaluators/client.py index 03d32a7a..b31ec525 100644 --- a/flatland/evaluators/client.py +++ b/flatland/evaluators/client.py @@ -24,6 +24,11 @@ logger.setLevel(logging.INFO) m.patch() +class TimeoutException(StopAsyncIteration): + """ Custom exception for evaluation timeouts. """ + pass + + class FlatlandRemoteClient(object): """ Redis client to interface with flatland-rl remote-evaluation-service @@ -168,7 +173,7 @@ class FlatlandRemoteClient(object): encoding="utf8" # remove for msgpack 1.0 ) print("Error received: ", error_dict) - raise StopAsyncIteration(error_dict["type"]) + raise TimeoutException(error_dict["type"]) # Push request in command_channels # Note: The patched msgpack supports numpy arrays @@ -392,7 +397,7 @@ if __name__ == "__main__": print("Episode Done") print("Reward : ", sum(list(all_rewards.values()))) break - except StopAsyncIteration as err: + except TimeoutException as err: print("Timeout: ", err) break diff --git a/flatland/evaluators/service.py b/flatland/evaluators/service.py index dfcae856..e8e285dc 100644 --- a/flatland/evaluators/service.py +++ b/flatland/evaluators/service.py @@ -479,20 +479,6 @@ class FlatlandRemoteEvaluationService: command = _get_next_command(self.command_channel, _redis) if self.verbose or self.report: print("Command Service: ", command) - # except timeout_decorator.timeout_decorator.TimeoutError: - # raise Exception( - # "Timeout of {}s in step {} of simulation {}".format( - # COMMAND_TIMEOUT, - # self.current_step, - # self.simulation_count - # )) - - # print("Timeout of {}s in step {} of simulation {}".format( - # COMMAND_TIMEOUT, - # self.current_step, - # self.simulation_count - # )) - # return {"type":messages.FLATLAND_RL.ENV_STEP_TIMEOUT} if self.use_pickle: command = pickle.loads(command) @@ -1006,7 +992,7 @@ class FlatlandRemoteEvaluationService: try: command = self.get_next_command() except timeout_decorator.timeout_decorator.TimeoutError: - # a timeout occured: send an error, and give -1.0 normalized score for this episode + # a timeout occurred: send an error, and give -1.0 normalized score for this episode if self.previous_command['type'] == messages.FLATLAND_RL.ENV_STEP: self.send_error({"type": messages.FLATLAND_RL.ENV_STEP_TIMEOUT}) @@ -1078,16 +1064,6 @@ class FlatlandRemoteEvaluationService: print("Overall Message Queue Latency : ", np.array(MESSAGE_QUEUE_LATENCY).mean()) self.handle_env_submit(command) - # elif command['type'] == messages.FLATLAND_RL.ENV_STEP_TIMEOUT: - # """ - # ENV_STEP_TIMEOUT - # - # The client took too long to give us the next command. - # - # """ - # - # print("client env_step timeout") - # self.handle_env_step_timeout(command) else: _error = self._error_template( -- GitLab