MCPcopy Index your code
hub / github.com/showlab/Code2Video / render_all_sections

Method render_all_sections

src/agent.py:596–665  ·  view source on GitHub ↗
(self, max_workers: int = 6)

Source from the content-addressed store, hash-verified

594 return section_id, False, None
595
596 def render_all_sections(self, max_workers: int = 6) -> Dict[str, str]:
597 print(f"🎥 Start parallel rendering of all section videos (up to {max_workers} processes)...")
598
599 tasks = []
600 for section in self.sections:
601 try:
602 task_data = (section, self.__class__, self.get_serializable_state())
603 tasks.append(task_data)
604 except Exception as e:
605 print(f"⚠️ Error preparing task data for {section.id}: {str(e)}")
606 continue
607
608 if not tasks:
609 print("❌ No valid tasks to execute")
610 return {}
611
612 results = {}
613 successful_count = 0
614 failed_count = 0
615
616 try:
617 with ProcessPoolExecutor(max_workers=max_workers) as executor:
618 future_to_section = {}
619 for task in tasks:
620 try:
621 future = executor.submit(self.render_section_worker, task)
622 future_to_section[future] = task[0].id
623 except Exception as e:
624 section_id = task[0].id if task and len(task) > 0 else "unknown"
625 print(f"⚠️ Error submitting task for {section_id}: {str(e)}")
626 failed_count += 1
627
628 for future in as_completed(future_to_section):
629 section_id = future_to_section[future]
630 try:
631 sid, success, video_path = future.result(timeout=300)
632
633 if success and video_path:
634 results[sid] = video_path
635 successful_count += 1
636 print(f"✅ {sid} video rendered successfully: {video_path}")
637 else:
638 failed_count += 1
639 print(f"⚠️ {sid} video rendering failed")
640
641 except Exception as e:
642 failed_count += 1
643 print(f"❌ {section_id} video rendering process error: {str(e)}")
644
645 except Exception as e:
646 print(f"❌ Critical error in parallel rendering process: {str(e)}")
647
648 # 更新结果并输出统计信息
649 self.section_videos.update(results)
650
651 total_sections = len(self.sections)
652 print(f"\n📊 Rendering Statistics:")
653 print(f" Total Sections: {total_sections}")

Callers 1

GENERATE_VIDEOMethod · 0.95

Calls 1

Tested by

no test coverage detected