0
$\begingroup$

I'm registering a depsgraph update handler but it is never called. Am I doing something wrong? What causes the handler to trigger?

def depsgraph_callback(scene, depsgraph):
  print('Do something')

def register():
  bpy.app.handlers.depsgraph_update_post.append(depsgraph_callback)

Edit:

The above code is only a snippet. I realize I didn't make that clear.

I think the issue is that I have the addon files located in the blender install directory, so that I don't have to re-zip every time I make a change. For some reason only the app handler isn't registering because of this, everything else like props seems to register fine. I have to manually disable and enable the addon for the handler to register. This doesn't happen when I zip the addon and install like normal, or if I register the handler using the blender text editor.

Anyone know what's going on here? Is this a bug? It's kind of a pain to have to re-enable the addon every time I make a change. Usually I will just restart blender and it will register as expected.

$\endgroup$
2
  • $\begingroup$ Does the handler get called ever or not? The first part of your question says "never" but the edit implies "after a re-register." In the second case, my answer below explains your issue; as does the manual page I pointed to. $\endgroup$ Commented Mar 23, 2022 at 19:15
  • 1
    $\begingroup$ @hilift please do not vandalize your posts. If it is no longer useful to you it may still be valuable for someone else in the same situation. $\endgroup$ Commented Jun 10, 2022 at 17:28

1 Answer 1

5
$\begingroup$
>>> def depsgraph_callback(scene, depsgraph):
...   print('Do something')
... 
>>> def register():
...   bpy.app.handlers.depsgraph_update_post.append(depsgraph_callback)
...   
>>> register()
>>> 

works just fine and produces

Read prefs: C:\Users\stupi\AppData\Roaming\Blender Foundation\Blender\2.93\config\userpref.blend
HardOps 0.9.87.29 available!
Do something
Do something
Do something
Do something
Do something

on my console window; but only after I've called the register routine.

Your problem seems to be that you haven't actually called register().

Also, if you wish the function to run whenever a new Blender instance is invoked, you need the @persistent decorator. That said, here's a complete working example, with a correct function definition:

import bpy
from bpy.app.handlers import persistent

@persistent
def depsgraph_callback(scene, depsgraph):
  print('Do something')

def register():
  bpy.app.handlers.depsgraph_update_post.append(depsgraph_callback)
  
register()

as described in the Application Handlers example.

$\endgroup$
1
  • $\begingroup$ Footnote: app handlers use "magic" Python/C interfaces in blender/bpy_app_handlers.c and although I can find no use for it, the callback has a variable length argument list implementation. $\endgroup$ Commented Mar 23, 2022 at 16:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .