Texture Bake at pre-render

Hey guys,

I'm trying to write a script that would bake a texture and load it in to material every time the render starts,

I tried using pre-render script and callback pre-render without a luck,
I guess you can not perform a render at pre-render stage,

How would you approach such a task?

Thanks,
Vladimir