scanny / python-pptx

Create Open XML PowerPoint documents in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create multiple slides with concurrent.futures

dieissonmartins opened this issue · comments

Any way to create slides in parallel with concurrent.futures?
My intention would be to create super large presentations in seconds

Screenshot from 2024-05-08 15-55-59

ex:
`
import concurrent.futures
from pptx import Presentation

def create_slide(number):
slide = prs.slides.add_slide(prs.slide_layouts[0])
title = slide.shapes.title
title.text = f'Slide {number}'

print(f'Creating slide {number}')

def main():
total_slides = 10
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
futures = [executor.submit(create_slide, i) for i in range(1, total_slides + 1)]
for future in concurrent.futures.as_completed(futures):
future.result()

prs.save('presentation.pptx')

if name == "main":
prs = Presentation()
main()`

I doubt it. At least not transparently. python-pptx is not design for concurrency and lxml would have to be concurrent too, which doesn't sound likely.

What I would do personally is profile the code and see what parts are taking the most time and then address those. It could be you could do some "preparation" concurrently, like gather things from databases and so on into memory and then write the PPTX in a single thread but using all those assembled resources.