How to wait for bpy.ops.render.render?

Hey

I’m sending a loop of jobs to render and I use this command as my drive >
bpy.ops.render.render(ctx, "INVOKE_DEFAULT", animation=False, write_still=True)

However as I do print before and after the command, I can see both prints happen instantly, and render does not block the execution of loop. What command can I use to “wait for render end/cancel” so that I can properly execute the loop?

Right now if I send 10 renders, only 1 will render, as the remaining 9 will run while the 1st one renders… Also any scene changes are also incorrect… sigh. Ideas?

TIA

You can remove “invoke_default” and it will work, however it will also show no rendering progress bar and it will freeze the UI until all the renders in the loop are done

There are handlers like render_post, render_finished, frame_post, etc.
https://docs.blender.org/api/current/bpy.app.handlers.html#bpy.app.handlers.render_post

The page shows how to add a handler for a particular event.