当前位置: 首页>>代码示例>>Python>>正文


Python websocket.WebSocketClosedError方法代码示例

本文整理汇总了Python中tornado.websocket.WebSocketClosedError方法的典型用法代码示例。如果您正苦于以下问题:Python websocket.WebSocketClosedError方法的具体用法?Python websocket.WebSocketClosedError怎么用?Python websocket.WebSocketClosedError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.websocket的用法示例。


在下文中一共展示了websocket.WebSocketClosedError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: open

# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketClosedError [as 别名]
def open(self):
        # 获取监控的path
        self.file_path = self.get_argument('file_path', '')
        MonitorHandler.clients.append(self)
        thread = MyThread(target=file_monitor, args=('%s.log' % self.file_path, self))
        MonitorHandler.threads.append(thread)
        self.stream.set_nodelay(True)

        try:
            for t in MonitorHandler.threads:
                if t.is_alive():
                    continue
                t.setDaemon(True)
                t.start()

        except WebSocketClosedError:
            client_index = MonitorHandler.clients.index(self)
            MonitorHandler.threads[client_index].stop()
            MonitorHandler.clients.remove(self)
            MonitorHandler.threads.remove(MonitorHandler.threads[client_index])

        logger.debug("Websocket: Monitor client num: %s, thread num: %s" % (len(MonitorHandler.clients),
                                                                            len(MonitorHandler.threads))) 
开发者ID:zsjtoby,项目名称:DevOpsCloud,代码行数:25,代码来源:run_server.py

示例2: send_data

# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketClosedError [as 别名]
def send_data(self, message):
        try:
            self.write_message(message, True)
        except websocket.WebSocketClosedError as err:
            self.on_error(err) 
开发者ID:mlperf,项目名称:training_results_v0.6,代码行数:7,代码来源:proxy.py

示例3: _send_response

# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketClosedError [as 别名]
def _send_response(self, response):
        try:
            self.write_message(json.dumps(response))
        except WebSocketClosedError:
            self._connected = False
            logging.warning("Dropping response to closed socket: %s",
               response, exc_info=True)
        except Exception as e:
            print "cant send", str(e)
            traceback.print_exc()
            print "RESPONSE", response.keys() 
开发者ID:darkwallet,项目名称:gateway,代码行数:13,代码来源:gateway.py

示例4: write_command

# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketClosedError [as 别名]
def write_command(self, cmd):
        assert isinstance(cmd, tuple) and len(cmd) >= 1
        bb = serializer.encode(cmd)
        try:
            self.write_message(bb, binary=True)
        except WebSocketClosedError:
            self.close(1000, 'closed by client') 
开发者ID:flexxui,项目名称:flexx,代码行数:9,代码来源:_tornadoserver.py

示例5: run

# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketClosedError [as 别名]
def run(self):
        try:
            super(MyThread, self).run()
        except WebSocketClosedError:
            pass 
开发者ID:zsjtoby,项目名称:DevOpsCloud,代码行数:7,代码来源:run_server.py

示例6: websocket_proxy_server

# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketClosedError [as 别名]
def websocket_proxy_server(url, key=""):
    """Create a RPC server that uses an websocket that connects to a proxy.

    Parameters
    ----------
    url : str
        The url to be connected.

    key : str
        The key to identify the server.
    """
    def create_on_message(conn):
        def _fsend(data):
            data = bytes(data)
            conn.write_message(data, binary=True)
            return len(data)
        on_message = base._CreateEventDrivenServer(
            _fsend, "WebSocketProxyServer", "%toinit")
        return on_message

    @gen.coroutine
    def _connect(key):
        conn = yield websocket.websocket_connect(url)
        on_message = create_on_message(conn)
        temp = _server_env(None)
        # Start connecton
        conn.write_message(struct.pack('<i', base.RPC_MAGIC), binary=True)
        key = "server:" + key
        conn.write_message(struct.pack('<i', len(key)), binary=True)
        conn.write_message(key.encode("utf-8"), binary=True)
        msg = yield conn.read_message()
        assert len(msg) >= 4
        magic = struct.unpack('<i', msg[:4])[0]
        if magic == base.RPC_CODE_DUPLICATE:
            raise RuntimeError("key: %s has already been used in proxy" % key)
        elif magic == base.RPC_CODE_MISMATCH:
            logging.info("RPCProxy do not have matching client key %s", key)
        elif magic != base.RPC_CODE_SUCCESS:
            raise RuntimeError("%s is not RPC Proxy" % url)
        msg = msg[4:]

        logging.info("Connection established with remote")

        if msg:
            on_message(bytearray(msg), 3)

        while True:
            try:
                msg = yield conn.read_message()
                if msg is None:
                    break
                on_message(bytearray(msg), 3)
            except websocket.WebSocketClosedError as err:
                break
        logging.info("WebSocketProxyServer closed...")
        temp.remove()
        ioloop.IOLoop.current().stop()
    ioloop.IOLoop.current().spawn_callback(_connect, key)
    ioloop.IOLoop.current().start() 
开发者ID:mlperf,项目名称:training_results_v0.6,代码行数:61,代码来源:proxy.py

示例7: websocket_proxy_server

# 需要导入模块: from tornado import websocket [as 别名]
# 或者: from tornado.websocket import WebSocketClosedError [as 别名]
def websocket_proxy_server(url, key=""):
    """Create a RPC server that uses an websocket that connects to a proxy.

    Parameters
    ----------
    url : str
        The url to be connected.

    key : str
        The key to identify the server.
    """
    def create_on_message(conn):
        def _fsend(data):
            data = bytes(data)
            conn.write_message(data, binary=True)
            return len(data)
        on_message = _ffi_api.CreateEventDrivenServer(
            _fsend, "WebSocketProxyServer", "%toinit")
        return on_message

    @gen.coroutine
    def _connect(key):
        conn = yield websocket.websocket_connect(url)
        on_message = create_on_message(conn)
        temp = _server_env(None)
        # Start connecton
        conn.write_message(struct.pack('<i', base.RPC_MAGIC), binary=True)
        key = "server:" + key
        conn.write_message(struct.pack('<i', len(key)), binary=True)
        conn.write_message(key.encode("utf-8"), binary=True)
        msg = yield conn.read_message()
        assert len(msg) >= 4
        magic = struct.unpack('<i', msg[:4])[0]
        if magic == base.RPC_CODE_DUPLICATE:
            raise RuntimeError("key: %s has already been used in proxy" % key)
        if magic == base.RPC_CODE_MISMATCH:
            logging.info("RPCProxy do not have matching client key %s", key)
        elif magic != base.RPC_CODE_SUCCESS:
            raise RuntimeError("%s is not RPC Proxy" % url)
        msg = msg[4:]

        logging.info("Connection established with remote")

        if msg:
            on_message(bytearray(msg), 3)

        while True:
            try:
                msg = yield conn.read_message()
                if msg is None:
                    break
                on_message(bytearray(msg), 3)
            except websocket.WebSocketClosedError as err:
                break
        logging.info("WebSocketProxyServer closed...")
        temp.remove()
        ioloop.IOLoop.current().stop()
    ioloop.IOLoop.current().spawn_callback(_connect, key)
    ioloop.IOLoop.current().start() 
开发者ID:apache,项目名称:incubator-tvm,代码行数:61,代码来源:proxy.py


注:本文中的tornado.websocket.WebSocketClosedError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。