How to keep the scene in sync between two threads? Or how to stop the UI getting redrawn when rendering?

I’m stuck on a problem. I’m trying to update the comp node tree before and after rendering using the render_init and render_complete handlers, but i’ve found that because those handlers arent exectued on the main thread it causes an access violation error due to the UI getting redrawn even if lock UI during rendering is set to true.

So I thought I’d set up a timer and queue to do the modifications on the main thread after the render_init and then once again after the render_complete. This works, but the problem is the modifications made to the node tree on the main thread are not recognised by the rendering thread.

Is there any way to update the scene on the rendering thread to match the scene on the main thread if the main thread has been modified aftrer render_init has been fired? Or is there any way to stop the viewport redrawing between render_init starting and render_complete finishing?