How do I iterate over keyframes in python? I'm trying to export animation data, but my bones never get updated from keyframe to keyframe. This is how I iterate over my actions and keyframes:

for action in bpy.data.actions:
    armature.animation_data.action = action
    bpy.ops.screen.frame_jump(0)
    bpy.context.scene.update()
    while {'FINISHED'} == bpy.ops.screen.keyframe_jump():
        bpy.context.scene.update()
        for boneName in bones_index:
            bone = armature.pose.bones[boneName]
            mat = glob_mat * mathutils.Matrix(bone.matrix)


The 'mat' variable is the bone matrix for each bone. Per frame, the 'mat' variable doesn't seem to change. For example, if I only look at the bone "Leg", the leg pose matrix doesn't seem to change keyframe to keyframe. The matrix is the correct matrix for frame 0, and it is different from my base pose. Am I not getting the pose matrices correctly? Or am I not correctly changing the scene? In the blender console, bpy.ops.screen.keyframe_jump() does exactly what I want, so I don't think that's the issue.
On some further investigation, and looking at other threads, I solved my issue by using the following method to update the scene.

bpy.context.scene.frame_set(bpy.context.scene.frame_current)


So now I'm thinking there is a bug in how bpy.ops.screen.keyframe_jump() is implemented. The line I added should theoretically do nothing (ie. setting the current frame to the current frame should be a no op). The strange thing is that my original implementation worked in the interactive console, but not when I put it in a text/export file and run it from there.