Bug ? starting timer in load_post handler does not work


#1

blender 2.8

there is the new timer api.
link

I CAN start the timer with a button (operator) call !

but NOT from load-post hander (in addon) !

# does not work: 
def timer_fired():
   # do stuff
   return 0.5 # seconds 

def handler():
    bpy.app.timers .register( timer_fired )
       
def my_register():
   bpy.app.handlers .load_post .append( handler )

#2

@jacqueslucke, any idea?


#3

Maybe the timer has to be marked as persistent.

https://docs.blender.org/api/blender2.8/bpy.app.timers.html#bpy.app.timers.register

(nevertheless this should not be necessary in load_post handler, will check it)


#4

Quick update: You have to make the handler and the timer persistent currently.


#5

that’s it – thank you !

# solution: make it persistent 

from bpy.app.handlers import persistent

@persistent   # do not discard, when file changes 
def timer_fired():
   # do stuff
   return 0.5 # seconds 

@persistent
def handler_load_post():
   if not bpy.app.timers  .is_registered( timer_fired ):
       bpy.app.timers .register( timer_fired, first_interval=1.0, persistent=True )
       
def my_init():
   bpy.app.handlers .load_post .append( handler_load_post )