Cycles Baking: Saving Images After Baking Complete

Hi!
I’m writing a script, that does some baking-related routine and have a problem with the code below:

Sometimes it seems, that For loop, which saves the images, saves them before object.bake finishes it’s work: I have the blank images as an output . No errors occur in the console.
In some cases baking takes too short time and I have the same empty images as an output.

If I run baking from Blender BAKE button and then run my script, in most cases baking and saving run OK.

I’ve tried to somehow catch the {“Running_Modal”} message from baker to run saving after baking, but haven’t succeeded.


        bpy.ops.object.bake(type='COMBINED', filepath="", width=texSize, height=texSize, margin=1, use_selected_to_active=False, cage_extrusion=0.0, cage_object="", normal_space='TANGENT', normal_r='POS_X', normal_g='POS_Y', normal_b='POS_Z', save_mode='EXTERNAL', use_clear=False, use_cage=False, use_split_materials=False, use_automatic_name=False, uv_layer="");
        
        for tex in bakedTextures: # Saving Images, previously created and stored in bakedTextures
            filename = texPath + tex.name + ".png";
            file = open(filename, 'w');
            file.close();
            tex.save_render(filename);

Thanks for any thoughts!