Synchronous --convert_to command

Hi,

I’m trying to automatically convert a document to a PDF and upload it to my server.
Using subprocess with python, I run /usr/bin/libreoffice --headless --convert-to pdf filepath_str.

After this I want to get some stats from my pdf, so I have pdfpath = filepath.with_suffix('.pdf') and assert pdfpath.exists(). This assertion fails.

However, if I add time.sleep(1) or while not pdfpath.exists(): continue before my assertion, it succeeds.

My conclusion is that the command returns before it has finished creating the pdf. What’s the best way to overcome this?