服务结束后清理服务器.

def clean(self):
        """服务结束后清理服务器."""
        # 服务结束阶段
        if self.running is False:
            return False
        logger.info("Stopping worker [%s]", self.pid)
        # 关闭server
        self.rpc_server.close()
        self.loop.run_until_complete(self.rpc_server.wait_closed())
        # 关闭连接
        # 完成所有空转连接的关闭工作
        for connection in MPProtocolServer.CONNECTIONS:
            connection.shutdown()

        # 等待由graceful_shutdown_timeout设置的时间
        # 让还在运转的连接关闭,防止连接一直被挂起
        start_shutdown = 0
        while MPProtocolServer.CONNECTIONS and (
                start_shutdown < self.graceful_shutdown_timeout):
            self.loop.run_until_complete(asyncio.sleep(0.1))
            start_shutdown = start_shutdown + 0.1

        # 在等待graceful_shutdown_timeout设置的时间后
        # 强制关闭所有的连接
        # for conn in MPProtocolServer.CONNECTIONS:
        #     conn.close()
        # 收尾阶段关闭所有协程,
        self.loop.run_until_complete(self.loop.shutdown_asyncgens())
        # 关闭loop
        self.loop.close()
        logger.info("Stopped worker [%s]", self.pid)
        return True