How to avoid multiple running instances of same handler function when running it from editor?
In simple cases when you're not having to deal with other handlers, you can clear all handlers before adding new ones:

bpy.app.handlers.frame_change_post.clear()


However for projects which are already using handlers, you may not want to remove everyone elses handlers, and instead replace only a handlers the script added.

Currently we don't have a convenient way to handle this, or at least Python doesn't make it so easy to reference a function defined in a previous execution.

This example script shows how the functions name and module can be used, append_function_unique is a function to append and remove previous instances.

import bpy

def append_function_unique(fn_list, fn):
    """ Appending 'fn' to 'fn_list',
        Remove any functions from with a matching name &amp; module.
    """
    fn_name = fn.__name__
    fn_module = fn.__module__
    for i in range(len(fn_list) - 1, -1, -1):
        if fn_list[i].__name__ == fn_name and fn_list[i].__module__ == fn_module:
            del fn_list[i]
    fn_list.append(fn)


def my_function(scene):
    print(scene)

def register():
    append_function_unique(bpy.app.handlers.frame_change_post, my_function)

if __name__ == "__main__":
    register()


Note: This is isn't such a problem for modules (add-ons or scripts you import). However scripts you run directly will use a module name of __main__. This means if you run multiple scripts directly, there may be function naming collisions - which is why this solution isn't ideal.