I am trying to use a timer for a function, but I need to provide it a parameter so I'm using the example from https://docs.blender.org/api/blender2.8/bpy.app.timers.html:

import bpy
import functools

def print_message(message):
    print("Message:", message)

bpy.app.timers.register(functools.partial(print_message, "Hello"), first_interval=2.0)

The problem is that I don't know how to unregister it. Trying with this:

if bpy.app.timers.is_registered(functools.partial(print_message, "World"):
    bpy.app.timers.unregister(functools.partial(print_message, "World")

Or this:

if bpy.app.timers.is_registered(print_message):

Or even this:

   if bpy.app.timers.is_registered(functools):

And a lot of other things, but that doesn't work. Any idea? Thanks!

  • 1
    $\begingroup$ bpy.app.timers has not unregister function, but timer function can return False to stop execution, try look at this $\endgroup$ – RUben Jun 2 '19 at 14:26
  • $\begingroup$ I have been able to unregister timers, it actually unregisters if I don't check if it's registered first (it does throw an error though, maybe it's trying to unregister itself twice). But the return None solution works great, so thanks for your help! $\endgroup$ – chafouin Jun 2 '19 at 14:34
  • 1
    $\begingroup$ @RUben bpy.app.timers has an unregister function listed here $\endgroup$ – Ray Mairlot Jun 2 '19 at 15:11
  • $\begingroup$ It's a bit weird that bpy.app.timers.is_registered doesn't work when using parameters. It must be expecting a specific argument that I don't know about. $\endgroup$ – chafouin Jun 3 '19 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.