[solved] Callbacks stay in memory between resets

Repro

First run this;

import pyblish.api
import pyblish_integration


def toggle_unwanted(instance, new_value, old_value):
    print "I shouldn't be here"

pyblish.api.register_callback("instanceToggled", toggle_unwanted)


class CollectInstance(pyblish.api.Collector):
    
    def process(self, context):
        
        context.create_instance("Some Instance", family="someFamily")


pyblish.api.register_plugin(CollectInstance)

pyblish_integration.show()

Followed by this:

import pyblish.api
import pyblish_integration


def toggle_wanted(instance, new_value, old_value):
    print "I want to be here"

pyblish.api.register_callback("instanceToggled", toggle_wanted)


class CollectInstance(pyblish.api.Collector):
    
    def process(self, context):
        
        context.create_instance("Some Instance", family="someFamily")


pyblish.api.register_plugin(CollectInstance)

pyblish_integration.show()

Looks like the callbacks doesn’t get cleared when resetting. You could have the workflow of only registering the callback when launching an application, but this isn’t very developer friendly. Secondly I would expect to keep my callbacks together with my plugins, if they are related.

Solution

Guessing you would need to run pyblish.api.deregister_callbacks() when resetting in the GUI, and pyblish core?

Yes, this. Sorry, can’t really see a way around this.

I’m not sure that’s a good idea, as it would deregister callbacks registered outside of plug-ins. :frowning:

hmm, good point, but it still doesn’t make for a developer friendly workflow. You basically have to restart the application every time you make a mistake.

I think you can deregister just the one you register, while you’re developing it.

import pyblish.api

def my_callback():
  pass

pyblish.api.register_callback("myEvent", my_callback)
pyblish.api.deregister_callback("myEvent", my_callback)

The workflow is the same as Maya’s native events I think.

Again, I’ll have to stress, that these are features not in the current release of Pyblish. It’s better we talk about them either on Gitter, or in the pull-request we made to implement the feature.