Main entry point to parallelize processing across sections. Returns the merged logs and token counters after processing all sections in parallel.
(
sections,
content,
outline,
style_logs,
critic_logs,
actor_logs,
img_logs,
slide_width,
slide_height,
name_to_hierarchy,
critic_template,
actor_template,
critic_agent,
actor_agent,
neg_img,
pos_img,
MAX_ATTEMPTS,
documentation,
total_input_token,
total_output_token,
max_workers=4
)
| 249 | } |
| 250 | |
| 251 | def parallel_by_sections( |
| 252 | sections, |
| 253 | content, |
| 254 | outline, |
| 255 | style_logs, |
| 256 | critic_logs, |
| 257 | actor_logs, |
| 258 | img_logs, |
| 259 | slide_width, |
| 260 | slide_height, |
| 261 | name_to_hierarchy, |
| 262 | critic_template, |
| 263 | actor_template, |
| 264 | critic_agent, |
| 265 | actor_agent, |
| 266 | neg_img, |
| 267 | pos_img, |
| 268 | MAX_ATTEMPTS, |
| 269 | documentation, |
| 270 | total_input_token, |
| 271 | total_output_token, |
| 272 | max_workers=4 |
| 273 | ): |
| 274 | """ |
| 275 | Main entry point to parallelize processing across sections. |
| 276 | |
| 277 | Returns the merged logs and token counters after processing all sections in parallel. |
| 278 | """ |
| 279 | # Because we’ll be modifying dictionaries (like style_logs, etc.), |
| 280 | # it can be safer to create a copy for the workers, then merge results |
| 281 | # after. (Below is a simple approach—depending on your scale, consider |
| 282 | # explicit concurrency controls or a database-backed approach.) |
| 283 | |
| 284 | # Summaries from each future |
| 285 | results = [] |
| 286 | |
| 287 | # We’ll store fresh copies for each section to avoid concurrency collisions |
| 288 | # on dictionary updates. If the data is large, you might want a more |
| 289 | # sophisticated synchronization or partition approach rather than naive copies. |
| 290 | with ThreadPoolExecutor(max_workers=max_workers) as executor: |
| 291 | futures = [] |
| 292 | |
| 293 | for section_name in sections: |
| 294 | # Make shallow copies or deep copies of logs |
| 295 | _style_logs = copy.deepcopy(style_logs) |
| 296 | _critic_logs = copy.deepcopy(critic_logs) |
| 297 | _actor_logs = copy.deepcopy(actor_logs) |
| 298 | _img_logs = copy.deepcopy(img_logs) |
| 299 | |
| 300 | futures.append(executor.submit( |
| 301 | process_section, |
| 302 | section_name, |
| 303 | content, |
| 304 | outline, |
| 305 | sections, |
| 306 | _style_logs, |
| 307 | _critic_logs, |
| 308 | _actor_logs, |