Skip to content

Commit

Permalink
If an agent throws an exception during act(…), exclude from rest of r…
Browse files Browse the repository at this point in the history
…ound
  • Loading branch information
fdraxler committed Mar 16, 2021
1 parent 33aa6fc commit 2d49d83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions agent_code/fail_agent/callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import numpy as np


def setup(self):
np.random.seed()


def act(agent, game_state: dict):
raise ValueError()
13 changes: 8 additions & 5 deletions agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ def act(self, game_state):
self.backend.send_event("act", game_state)

def wait_for_act(self):
action, think_time = self.backend.get_with_time("act")
self.last_action = action
return action, think_time
try:
action, think_time = self.backend.get_with_time("act")
self.last_action = action
return action, think_time
except BaseException:
return 'WAIT', float("inf")

def round_ended(self):
self.backend.send_event("end_of_round", self.last_game_state, self.last_action, self.events)
Expand Down Expand Up @@ -214,7 +217,7 @@ def process_event(self, event_name, *event_args):
self.wlogger.debug(f"Got result from callback#{event_name} in {duration:.3f}s.")

self.result_queue.put((event_name, duration, event_result))
except Exception as e:
except BaseException as e:
self.wlogger.error(f"An exception occurred while calling {event_name}: {e}")
self.result_queue.put((event_name, 0, e))

Expand Down Expand Up @@ -245,7 +248,7 @@ def get_with_time(self, expect_name: str, block=True, timeout=None) -> Tuple[Any
event_name, compute_time, result = self.result_queue.get(block, timeout)
if event_name != expect_name:
raise ValueError(f"Logic error: Expected result from event {expect_name}, but found {event_name}")
if isinstance(result, Exception):
if isinstance(result, BaseException):
raise result
return result, compute_time
except queue.Empty:
Expand Down

0 comments on commit 2d49d83

Please sign in to comment.