I would suggest using the Blender command line interface (CLI) to trigger the script execution and rendering. The CLI is described in the Blender documentation.
For instance you could start Blender from the command line, let it run a python script and then render a frame using the following command (you will have to add the correct paths to the relevant files). The following command renders frame 0 of project.blend after the script.py has been executed.
.\blender.exe project.blend -b -P script.py -o //frame_ -f 0
-b
or --background
starts Blender without a user interface.
-P
or --python
allows to run a script.
-o
or --render-output
defines how the rendered files will be namesnamed and where they will be stored. //
denotes the current working directory.
-f
or --render-frame
tells Blender to render a specific frame.
In case you don't want to execute Blender with this command manually, you can use subprocess
in a another python script to start Blender. The following function is an example of how you could start Blender from another python script. As arguments you need to pass the path to Blender, the project and the script and it will start another process that runs Blender with these arguments.
import argparse
import subprocess
def run_blender(blender, project, script):
output = subprocess.check_output([blender,
project,
'--background',
'--python', script,
'--render-output', '//frame_',
'--render-frame', '0'])
print(output.decode("utf-8"))