# How to run a script before rendering

After answering the question Always render the visible objects I realized that, rather than running the script manually, it would be easier to have it run automagically, once, before rendering (that includes the building BVH phase), however, I couldn't find a way to do this. How would that be done?

bpy.app.handlers.render_pre.append(function_name)
Make sure your function takes self as a parameter, like so:
function_name(self): print("Test")