# When I try to call a mode_set operator from one of these handlers, the traceback blender crashes

I tryied to come with a elegant solution fot easily removing handlers from blender.

I was thinking in something like that. The cool part is that in this case you can have independent namespaces for each handler that is a instance of class.

But I would like to hear from the experient addon writers if that gona work well, I find handlers a bit scary to work with.

like: when I try to call an mode_set operator from one of these handlers, the traceback freak out and blender craches.

import bpy
from bpy.app.handlers import persistent

class WrappingHandler:

def __init__(self, handler_list = None):

self.setup()
self.handler_list = handler_list
if handler_list is not None:
print("handler appended")
handler_list.append(self.wrapper)

def setup(self):
pass

def __call__(self, scene):
pass

def destroy(self):
self.handler_list.remove(self.wrapper)

@persistent
def wrapper(self, scene):
return self.__call__(scene)

class AutoDestructibleHandler(WrappingHandler):

def __call__(self, scene):

bpy.ops.object.mode_set(mode="OBJECT")

self.destroy()

if __name__ == "__main__":
AutoDestructibleHandler(bpy.app.handlers.scene_update_pre)

• okay, I'll do that. – Jeacom Apr 1 '18 at 2:30
• I find using a prefix on my handler method names and [hander.remove(f) for f in hander if f.__name__.startswith("PREFIX")] to remove them all, is a rather bulletproof, if not elegant, solution, – batFINGER Apr 1 '18 at 13:11