code: def publish(self):
          
  
          def get_data():
              model = self.data["models"]["item"]
  
              # Communicate with host to retrieve current plugins and instances
              # This can potentially take a very long time; it is run
              # asynchronously and initiates processing once complete.
              host_plugins = dict((p.id, p) for p in self.host.cached_discover)
              host_context = dict((i.id, i) for i in self.host.cached_context)
  
              plugins = list()
              instances = list()
  
              for plugin in models.ItemIterator(model.plugins):
  
                  # Exclude Collectors
                  if pyblish.lib.inrange(
                          number=plugin.order,
                          base=pyblish.api.Collector.order):
                      continue
  
                  plugins.append(host_plugins[plugin.id])
  
              for instance in models.ItemIterator(model.instances):
                  instances.append(host_context[instance.id])
  
              return plugins, instances
  
          def on_data_received(args):
              self.run(*args, callback=on_finished)
  
          def on_finished():
              self.host.emit("published", context=None)
  
          util.defer(get_data, callback=on_data_received)
docs: Start asynchonous publishing
  
          Publishing takes into account all available and currently
          toggled plug-ins and instances.