# bpy.ops.render.render() freezes Blender when used in an addon

I'm trying to build an addon that makes it possible to batch render using Cycles directly from the UI. I've started from a script find a while ago here but I cannot find anymore to link for reference. Anyways, the script worked correctly but without UI so I've decided to port it into an addon that permits to make the same actions but when Blender is open.

Here the problem: my addon works. It correctly creates the panel, buttons etc, but when I click the render button Blender freezes and the only way to "recover" is by force-closing it. I've debugged the code line by line and find that the problem is when Blender calls the render.render operator (bpy.ops.render.render()), and that the same problem appears when you call the operator from Blender build-in Python terminal.

I know that the render.render operator is a C implementation and not a Python one, so maybe the problem resides in that, but the normal render button is implemented in the same way (it seems to me) and it works, and if in my addons I change the call to my operator render.batch with the call to render.render the behavior is normal (it renders the chosen camera), so I don't know what I'm doing wrong.

Below my new operator implementation, maybe someone knows how to help me.

class BatchRender(bpy.types.Operator):
"""Batch Render"""
bl_idname = "render.batch"
bl_label = "Subsequently render all selected cameras"
bl_options = {'REGISTER', 'UNDO'}

def execute(self, context):

sceneKey = bpy.data.scenes.keys()[0]
r = 0

for item in cameras:
if item.custom.isSelected:
bpy.data.scenes[sceneKey].camera = item
bpy.data.scenes[sceneKey].render.filepath = "//" + item.name + str(r)
bpy.ops.render.render(write_still=True)
r += 1
else:
self.report({'INFO'}, "No camera selected for batch rendering")

return {'FINISHED'}


Some more little clarifications:

• cameras is a list of the cameras present into the scene
• custom.isSelected is a camera properties implemented by me before into the addons, is a boolean property and work correctly (I've tested line by line the code as I've said before)