code: def listen(self):
          
  
          def _listen():
              while True:
                  line = self.host.channels["parent"].get()
                  payload = json.loads(line)["payload"]
  
                  # We can't call methods directly, as we are running
                  # in a thread. Instead, we emit signals that do the
                  # job for us.
                  signal = {
  
                      "show": "shown",
                      "hide": "hidden",
                      "quit": "quitted",
                      "publish": "published",
                      "validate": "validated",
  
                      "rise": "risen",
                      "inFocus": "inFocused",
                      "outFocus": "outFocused",
  
                  }.get(payload["name"])
  
                  if not signal:
                      print("'{name}' was unavailable.".format(
                          **payload))
                  else:
                      try:
                          getattr(self, signal).emit(
                              *payload.get("args", []))
                      except Exception:
                          traceback.print_exc()
  
          thread = threading.Thread(target=_listen)
          thread.daemon = True
          thread.start()
docs: Listen on incoming messages from host
  
          TODO(marcus): We can't use this, as we are already listening on stdin
              through client.py. Do use this, we will have to find a way to
              receive multiple signals from the same stdin, and channel them
              to their corresponding source.