Skip to content
Advertisement

How to wait until java compilation of PlantUML diagrams is completed, in Python?

Context

I’ve written a Python code that:

  1. First generates PlantUML .uml files.
  2. Then runs a Java command to locally compile those .uml files into .png diagrams.
  3. Exports those diagrams into a /images directory for latex compilation.
  4. Then compiles a latex document that integrates those generated PlantUML diagrams.

Code

The Python that compiles the .uml files into .png files is:

JavaScript

And I have written a method that waits until all .png files are created:

JavaScript

Issue

The Python code proceeds before the images are completely generated by the Java process.

This means the images are created but it takes a while before they are actually filled with data. Even when they are filled with data it takes a while before they are completed. For example some_diagram.png may increase in file size from 0 kb, to 800 bytes to 1.2 kb over the timespan of a few seconds. So my “await_and_verify_compilation_results` does not wait until the generation of the pictures is completed.

Question

How can I make the Python code wait until the Java process/PlantUML generation of the .png files is completed?

Considerations

Since the .png files are generated automatically, I do not know what their final file size would be. I can set a manual pause of x seconds after each png to ensure they are completed on my device, but I would not want others with a faster device to have to wait on my buffer. Additionally such a hardcoded loiter may be unreliable, and inefficient compilation-timewise. So I think the most simple solution would be to modify the python function that calls the Java function. I have not yet found out how to make that wait, nor have I found how I can make the Java function signal that is is completed. (The PlantUML .jar file is downloaded automatically and I would prefer not to tamper with their file).

Advertisement

Answer

As Gonzalo Odiard already suggested in the comments, the solution could be found by using subprocess.call instead of subprocess.Popen. So a solution looked like:

JavaScript

It was verified on Ubuntu 21.04 Using Python 3.6.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement