def check_children(self):
        """
        Check for output from command channels and daemons, remove daemons
        that died from list of running ones and place them in restart queue.
        """
        for daemon in self.poll.poll():
            if isinstance(daemon, control_socket.ControlSocket):
                client = daemon.accept()
                self.poll.add(client)
                continue

            if isinstance(daemon, control_socket.ControlSocketClient):
                self.handle_command(daemon)
                continue

            # isinstance(daemon, daemon.Daemon)
            self.handle_daemon_output(daemon)

        # check if all the daemons are still running
        for dname in self.running.keys():  # self.running can change
            daemon = self.running[dname]
            if not daemon.is_alive():
                # close daemon's pipe, in case it was still opened
                # FIXME: this can loose some of the daemon's output
                self.poll.remove(daemon)
                daemon.close()
                del self.running[dname]
                self.restart_queue.daemon_died(dname)
 def handle_daemon_output(self, daemon):
     """
     Handle output from a daemon according to daemon's definition: either
     log it or forward it as a message.
     """
     line = daemon.readline()
     if line == "":  # EOF, but this doesn't mean that the daemon died yet
         self.poll.remove(daemon)
         daemon.close()
     else:
         # TODO: process the line (JSON-decode and forward it or log using
         # logging module)
         pass