Snap FK IK and reverse with python scripting

I recently developed this little python script to use snap FK to IK and IK to FK.
Like this video example

Here the code and the blend file
https://3dminfographie.com/images/graphisme-3d/bug/Snap_ik_fk.7z

I’m doing matrix equalities to be able to plate the bones one on top of the other.
https://docs.blender.org/api/current/bpy.types.PoseBone.html#bpy.types.PoseBone.matrix

However, when I want to make these matrix equalities my code becomes disgusting because I add a for loop with 4 or 15 iterations to refresh the bpy.ops.wm.redraw_timer() window depending on the type of snap.

I must be going about this the wrong way, but I find that my code is horribly constructed in this way.

With the rig I’ve created, is there a solution to avoid refreshing?

    def execute(self, context):
        for i in range(0, 4):
            FK2IK_FLeg_L(context)
            bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
        return { 'FINISHED'}

My rig remains basically simple.
Is there another way to avoid these for loops with wm.redraw_timer?