當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。