How to set bpy.context.window.scene in the right context? I would like to set the active scene with bpy.context.window.scene = my_scene

Now the problem is that normally this works if you are in the right context, the problem (in my specific case) is inside a function that is executed immediately after bpy.ops.render.render ('INVOKE_DEFAULT')
immediately after the end of the render I get:

for s in bpy.data.scenes:
     if s == my_scene:
         context.window.scene = s


AttributeError: 'NoneType' object has no attribute 'scene'

so I guess currently the context has changed to that of rendering, am I wrong?

How can I solve this?
I think the answer to my question is a simple copy of context. So:

ctx = bpy.context.copy()

bpy.ops.render.render('INVOKE_DEFAULT')

###This is handled with some handlers, but essentially seems to work with a simple context copy

for s in bpy.data.scenes:
     if s == my_scene:
         ctx['window'].scene = s


I think this is the answer to my question, but I won't vote for it right now as I could probably cheat in future problems.
For now everything seems to work ok.