Skip to content

Commit 0c55329

Browse files
committed
Huskybench fix wip (sometimes timeout?)
1 parent 12e3921 commit 0c55329

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

codeclash/games/huskybench/huskybench.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from codeclash.agents.player import Player
55
from codeclash.games.game import CodeGame, RoundStats
6+
from codeclash.utils.environment import create_file_in_container
67

78
HB_LOG_ENGINE = "engine.log"
89
HB_REGEX_SCORE = re.compile(r"Player\s(\d+)\sdelta\supdated\:[\d\s\-\+\=]+,\smoney\:\s\d+\s\-\>\s(\d+)")
@@ -26,18 +27,22 @@ def __init__(self, config, *, tournament_id: str, local_output_dir: Path):
2627
self.run_cmd_round += f" --{arg} {val}"
2728

2829
def execute_round(self, agents: list[Player]):
29-
try:
30-
cmd = f"{self.run_cmd_round} > {self.log_env / HB_LOG_ENGINE} &"
31-
self.logger.debug(f"Starting game engine with command: {cmd}")
32-
self.environment.execute(cmd)
33-
for agent in agents:
34-
cmd = f"python client/main.py --port 8000 > {self.log_env / f'{agent.name}.log'} &"
35-
self.logger.debug(f"Adding agent with command: {cmd}")
36-
self.environment.execute(cmd, cwd=f"/{agent.name}")
37-
finally:
38-
# Kill all python servers when done
39-
self.environment.execute("pkill -f 'python client/main.py' || true")
40-
self.environment.execute("pkill -f 'python engine/main.py' || true")
30+
cmd = f"{self.run_cmd_round} > {self.log_env / HB_LOG_ENGINE} 2>&1 &"
31+
self.logger.debug(f"Starting game engine with command: {cmd}")
32+
script = [cmd, "sleep 0.5"]
33+
for agent in agents:
34+
cmd = f"cd /{agent.name} && python client/main.py --port 8000 > {self.log_env / f'{agent.name}.log'} 2>&1 &"
35+
self.logger.info(f"Adding player {agent.name} with command: {cmd}")
36+
script.append(cmd)
37+
script.append("wait")
38+
create_file_in_container(
39+
container=self.environment, content="\n".join(script), dest_path="/testbed/run_game.sh"
40+
)
41+
42+
current = self.environment.config.timeout
43+
self.environment.config.timeout = 60
44+
self.environment.execute("chmod +x run_game.sh; ./run_game.sh")
45+
self.environment.config.timeout = current
4146

4247
def get_results(self, agents: list[Player], round_num: int, stats: RoundStats):
4348
map_id_to_agent = {}

0 commit comments

Comments
 (0)