Callback II
You can emit and catch your own signals.
1
import pyblish.api
2
3
class MyCollector(pyblish.api.ContextPlugin):
4
order = pyblish.api.CollectorOrder
5
6
def process(self, context):
7
pyblish.api.emit("myEvent", data="myData")
Copied!
You can then catch this signal anywhere in your program.
1
import pyblish.api
2
3
def on_my_event(data):
4
print(data)
5
6
pyblish.api.register_callback("myEvent", on_my_event)
Copied!
Callbacks can be useful for, amongst other things:
    Deep customisation
    Advanced logging
    Tighter integration
On a technical note, callbacks are run on the main thread and block until finished. This means that if for example one of your callbacks would take 10 seconds to finish, publishing overall will take 10 seconds longer. On the upside, it also means that the Context will accurately reflect the current state at the time of a signal emitting.
Last modified 1yr ago
Copy link