| 505 | return False |
| 506 | |
| 507 | def generate_codes(self) -> Dict[str, str]: |
| 508 | if not self.sections: |
| 509 | raise ValueError(f"{self.learning_topic} Please generate teaching sections first") |
| 510 | |
| 511 | def task(section): |
| 512 | try: |
| 513 | self.generate_section_code(section, attempt=1) |
| 514 | return section.id, None |
| 515 | except Exception as e: |
| 516 | return section.id, e |
| 517 | |
| 518 | with ThreadPoolExecutor(max_workers=6) as executor: |
| 519 | futures = {executor.submit(task, section): section for section in self.sections} |
| 520 | for future in as_completed(futures): |
| 521 | section_id, err = future.result() |
| 522 | if err: |
| 523 | print(f"❌ {self.learning_topic} {section_id} code generation failed: {err}") |
| 524 | |
| 525 | return self.section_codes |
| 526 | |
| 527 | def render_section(self, section: Section) -> bool: |
| 528 | section_id = section.id |