Depends on: https://developer.blender.org/D3978
The depsgraph_update_pre/post handlers are useful when one is monitoring specific properties in Blender.
To fully replace the behavior of the scene_update_post/pre handlers we need more though.
This patch proposes a new bpy_extras.callback_utils module with two new functions (whose name can still change).
- set_interval(function, interval): This registers a callback that should be called every interval seconds. When the function returns True, it will run again in the next interval. Otherwise it will be unregistered automatically.
- run_in_main_thread: Sometimes it is useful to run a separate thread in Blender (e.g. for a simple server or for Python debugging). Currently there is no reliable way to change any Blender data from a separate thread. Using this utility function, addon developers can register a callback that will be executed one time, when Blender is in the right state.
Internally this behavior is implemented using a new _always handler that should maybe not be part of the official API. The behavior of it can still be archieved by registering a function with zero interval. For simplicity I think it is a good idea to implement this functionality in Python. The always_handler function tries to be as fast as possible in the common case.