def main_loop(self, container_id):
        """
        The 'internal' loop. Listen to SBus, receive datagram,
        dispatch command, report back.
        """

        # Create SBus. Listen and process requests
        sbus = SBus()
        fd = sbus.create(self.pipe_path)
        if fd < 0:
            self.logger.error("Failed to create SBus. exiting.")
            return

        b_iterate = True
        b_status = True
        error_text = ''

        while b_iterate:
            rc = sbus.listen(fd)
            if rc < 0:
                self.logger.error("Failed to wait on SBus. exiting.")
                return
            self.logger.debug("Wait returned")

            dtg = sbus.receive(fd)
            if not dtg:
                self.logger.error("Failed to receive message. exiting.")
                return

            try:
                # TODO(takashi): We had better use contextmanager
                outfd = dtg.get_first_file_of_type(SBUS_FD_OUTPUT_OBJECT)
            except Exception:
                self.logger.error("Received message does not have outfd."
                                  " continuing.")
                continue
            else:
                self.logger.debug("Received outfd %d" % outfd.fileno())

            b_status, error_text, b_iterate = \
                self.dispatch_command(dtg, container_id)

            self.log_and_report(outfd, b_status, error_text)
            outfd.close()

        # We left the main loop for some reason. Terminating.
        self.logger.debug('Leaving main loop')
dataset/ETHPy150Open openstack/storlets/Engine/storlet_daemon_factory/daemon_factory.py/daemon_factory.main_loop/original