Skip to content

Commit c4cd3c3

Browse files
committed
Run agents in parallel
1 parent feeaca0 commit c4cd3c3

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

.cursor/rules/style.mdc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ alwaysApply: true
1919
11. Not every exception has to be caught. Exceptions are a good way to show problems to a user.
2020
12. Don't catch exceptions just to re-raise them slightly differently. This doesn't add any value.
2121
13. Write concise code and thing of elegant solution.
22+
14. When logging exceptions, always include `exc_info=True` to capture the full traceback.
2223

2324
## Test style
2425

codeclash/tournaments/pvp.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import json
6+
from concurrent.futures import ThreadPoolExecutor
67

78
from codeclash.agents import get_agent
89
from codeclash.agents.player import Player
@@ -102,8 +103,14 @@ def run_training_round(self, round_num: int) -> None:
102103
f"logs/rounds/{round_num}/",
103104
)
104105

105-
for agent in self.agents:
106-
self.run_agent(agent, round_num)
106+
with ThreadPoolExecutor() as executor:
107+
futures = [executor.submit(self.run_agent, agent, round_num) for agent in self.agents]
108+
for future in futures:
109+
try:
110+
future.result()
111+
except Exception as e:
112+
self.logger.critical(f"Agent execution failed: {e}", exc_info=True)
113+
raise
107114

108115
self.logger.info("Round completed.")
109116

0 commit comments

Comments
 (0)