|
1 | 1 | import os |
2 | 2 | import subprocess |
| 3 | +import traceback |
3 | 4 | from abc import ABC, abstractmethod |
4 | 5 | from collections import Counter |
5 | 6 | from pathlib import Path |
|
10 | 11 |
|
11 | 12 | from codeclash.agents.abstract import Player |
12 | 13 | from codeclash.constants import DIR_LOGS, DIR_WORK, GH_ORG |
13 | | -from codeclash.games.utils import copy_between_containers |
| 14 | +from codeclash.games.utils import copy_between_containers, copy_file_from_container |
14 | 15 | from codeclash.utils.environment import assert_zero_exit_code |
15 | 16 |
|
16 | 17 |
|
@@ -121,13 +122,34 @@ def execute_round(self, agents: list[Player]): |
121 | 122 |
|
122 | 123 | def _post_round_setup(self, agents: list[Player]): |
123 | 124 | for agent in agents: |
124 | | - copy_between_containers( |
125 | | - self.environment, |
126 | | - agent.environment, |
127 | | - self.round_log_path, |
128 | | - f"{agent.environment.config.cwd}/logs/round_{self.round}.log", |
129 | | - ) |
130 | | - print(f"Copied round log to {agent.name}'s container.") |
| 125 | + try: |
| 126 | + copy_between_containers( |
| 127 | + self.environment, |
| 128 | + agent.environment, |
| 129 | + self.round_log_path, |
| 130 | + f"{agent.environment.config.cwd}/logs/round_{self.round}.log", |
| 131 | + ) |
| 132 | + except Exception: |
| 133 | + print( |
| 134 | + f"Error copying round log to {agent.name}'s container: {traceback.format_exc()}" |
| 135 | + ) |
| 136 | + else: |
| 137 | + print(f"Copied round log to {agent.name}'s container.") |
| 138 | + |
| 139 | + try: |
| 140 | + copy_file_from_container( |
| 141 | + self.environment, |
| 142 | + self.round_log_path, |
| 143 | + DIR_LOGS / f"{self.game_id}/round_{self.round}.log", |
| 144 | + ) |
| 145 | + except Exception: |
| 146 | + print( |
| 147 | + f"Error copying round log to {agent.name}'s container: {traceback.format_exc()}" |
| 148 | + ) |
| 149 | + else: |
| 150 | + print( |
| 151 | + f"Copied round log from {agent.name}'s container to local log dir." |
| 152 | + ) |
131 | 153 | print(f"Round {self.round} completed.") |
132 | 154 |
|
133 | 155 | def run_round(self, agents: list[Player]): |
|
0 commit comments