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


Python websocket.WebSocketTimeoutException方法代码示例

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


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

示例1: testInternalRecvStrict

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def testInternalRecvStrict(self):
        sock = ws.WebSocket()
        s = sock.sock = SockMock()
        s.add_packet(six.b("foo"))
        s.add_packet(socket.timeout())
        s.add_packet(six.b("bar"))
        # s.add_packet(SSLError("The read operation timed out"))
        s.add_packet(six.b("baz"))
        with self.assertRaises(ws.WebSocketTimeoutException):
            sock.frame_buffer.recv_strict(9)
        # if six.PY2:
        #     with self.assertRaises(ws.WebSocketTimeoutException):
        #         data = sock._recv_strict(9)
        # else:
        #     with self.assertRaises(SSLError):
        #         data = sock._recv_strict(9)
        data = sock.frame_buffer.recv_strict(9)
        self.assertEqual(data, six.b("foobarbaz"))
        with self.assertRaises(ws.WebSocketConnectionClosedException):
            sock.frame_buffer.recv_strict(1) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:22,代码来源:test_websocket.py

示例2: testRecvTimeout

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def testRecvTimeout(self):
        sock = ws.WebSocket()
        s = sock.sock = SockMock()
        s.add_packet(six.b("\x81"))
        s.add_packet(socket.timeout())
        s.add_packet(six.b("\x8dabcd\x29\x07\x0f\x08\x0e"))
        s.add_packet(socket.timeout())
        s.add_packet(six.b("\x4e\x43\x33\x0e\x10\x0f\x00\x40"))
        with self.assertRaises(ws.WebSocketTimeoutException):
            sock.recv()
        with self.assertRaises(ws.WebSocketTimeoutException):
            sock.recv()
        data = sock.recv()
        self.assertEqual(data, "Hello, World!")
        with self.assertRaises(ws.WebSocketConnectionClosedException):
            sock.recv() 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:18,代码来源:test_websocket.py

示例3: _data_thread

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def _data_thread(self):
        try:
            conn = create_connection(self.addr)
        except Exception:
            self._controller_q.put('restart_data')
            return

        while self.running:
            try:
                data = conn.recv()
                data = json.loads(data)
            except WebSocketTimeoutException:
                self._controller_q.put('restart_data')
                return
            try:
                pair = data['MarketDataIncrementalRefresh']['symbol']
                endpoint = 'MarketDataIncrementalRefresh'
            except KeyError:
                pair = data['MarketDataSnapshotFullRefresh']['symbol']
                endpoint = 'MarketDataSnapshotFullRefresh'
            self.data_q.put((endpoint, pair, data[endpoint], time.time())) 
开发者ID:Crypto-toolbox,项目名称:bitex,代码行数:23,代码来源:hitbtc.py

示例4: _trade_thread

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def _trade_thread(self):
        try:
            conn = create_connection(self.trader_addr)
        except Exception:
            log.exception('Trader Thread Error!')
            self._controller_q.put('restart_trader')
            return

        while self.running:
            try:
                data = conn.recv()
            except WebSocketTimeoutException:
                self._controller_q.put('restart_data')
                return
            self.data_q.put(json.loads(data))

            try:
                payload = self.trade_command_q.get()
            except Empty:
                continue

            try:
                conn.send(self.sign(payload))
            except (WebSocketTimeoutException, ConnectionResetError):
                continue 
开发者ID:Crypto-toolbox,项目名称:bitex,代码行数:27,代码来源:hitbtc.py

示例5: __connect

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def __connect(self, wsURL, symbol):
        '''Connect to the websocket in a thread.'''
        self.logger.debug("Starting thread")

        self.ws = websocket.WebSocketApp(wsURL,
                                         on_message=self.__on_message,
                                         on_close=self.__on_close,
                                         on_open=self.__on_open,
                                         on_error=self.__on_error,
                                         header=self.__get_auth())

        self.wst = threading.Thread(target=lambda: self.ws.run_forever())
        self.wst.daemon = True
        self.wst.start()
        self.logger.debug("Started thread")

        # Wait for connect before continuing
        conn_timeout = 5
        while not self.ws.sock or not self.ws.sock.connected and conn_timeout:
            sleep(1)
            conn_timeout -= 1
        if not conn_timeout:
            self.logger.error("Couldn't connect to WS! Exiting.")
            self.exit()
            raise websocket.WebSocketTimeoutException('Couldn\'t connect to WS! Exiting.') 
开发者ID:economicnetwork,项目名称:archon,代码行数:27,代码来源:bitmex_websocket.py

示例6: recv

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def recv(self):
        if not self.client.connected:
            self._try_to_establish_connection()
        while self._is_active():
            try:
                data = self.client.recv()
                self._on_successful_connect()
                return data
            except WebSocketTimeoutException:
                raise
            except WebSocketConnectionClosedException:
                if self._is_active():
                    self._handle_lost_connection()
                else:
                    raise
            except WebsocketNotConnectedException:
                if self._is_active():
                    self._handle_lost_connection()
            except Exception:
                if self._is_active():
                    self._handle_lost_connection() 
开发者ID:neptune-ai,项目名称:neptune-client,代码行数:23,代码来源:reconnecting_websocket.py

示例7: __connect_to_tab

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def __connect_to_tab(self, tab_key):
		assert tab_key not in self.soclist

		cr_tab_meta = self._get_cr_tab_meta_for_key(tab_key)

		if not 'webSocketDebuggerUrl' in cr_tab_meta:
			raise cr_exceptions.ChromeConnectFailure("Tab %s has no 'webSocketDebuggerUrl' (%s)" % (tab_key, self.tablist))

		wsurl = cr_tab_meta['webSocketDebuggerUrl']

		try:
			self.log.info("Setting up websocket connection for key '%s'", tab_key)
			self.soclist[tab_key] = websocket.create_connection(wsurl)
			self.soclist[tab_key].settimeout(self.websocket_timeout)

		except (socket.timeout, websocket.WebSocketTimeoutException):
			raise cr_exceptions.ChromeCommunicationsError("Could not connect to remote chromium.") 
开发者ID:fake-name,项目名称:ChromeController,代码行数:19,代码来源:transport.py

示例8: ___recv

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def ___recv(self, tab_key, timeout=None):

		try:
			if timeout:
				self.soclist[tab_key].settimeout(timeout)

			tmp = self.soclist[tab_key].recv()
			self.log.debug("		Received: '%s'", tmp)

			decoded = json.loads(tmp)
			return decoded
		except (socket.timeout, websocket.WebSocketTimeoutException):
			return None
		except websocket.WebSocketConnectionClosedException:
			raise cr_exceptions.ChromeCommunicationsError("Websocket appears to have been closed. Is the"
				" remote chromium instance dead?")
		finally:
			self.soclist[tab_key].settimeout(self.websocket_timeout) 
开发者ID:fake-name,项目名称:ChromeController,代码行数:20,代码来源:transport.py

示例9: __connect

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def __connect(self, wsURL, symbol):
        '''Connect to the websocket in a thread.'''
        self.logger.debug("Starting thread")

        self.ws = websocket.WebSocketApp(wsURL,
                                         on_message=self.__on_message,
                                         on_close=self.__on_close,
                                         on_open=self.__on_open,
                                         on_error=self.__on_error,
                                         header=None)

        self.wst = threading.Thread(target=lambda: self.ws.run_forever())
        self.wst.daemon = True
        self.wst.start()
        self.logger.debug("Started thread")

        # Wait for connect before continuing
        conn_timeout = 5
        while not self.ws.sock or not self.ws.sock.connected and conn_timeout:
            sleep(1)
            conn_timeout -= 1
        if not conn_timeout:
            self.logger.error("Couldn't connect to WS! Exiting.")
            self.exit()
            raise websocket.WebSocketTimeoutException('Couldn\'t connect to WS! Exiting.') 
开发者ID:mottio-cancer,项目名称:py_bitflyer_jsonrpc,代码行数:27,代码来源:py_bitflyer_jsonrpc.py

示例10: __connect

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def __connect(self, wsURL, symbol):
        '''Connect to the websocket in a thread.'''
        self.logger.debug("Starting thread")

        self.ws = websocket.WebSocketApp(wsURL,
                                         on_message=self.__on_message,
                                         on_close=self.__on_close,
                                         on_open=self.__on_open,
                                         on_error=self.__on_error,
                                         header=self.__get_auth())

        self.wst = threading.Thread(target=lambda: self.ws.run_forever())
        self.wst.setDaemon(True)
        self.wst.start()
        self.logger.debug("Started thread")

        # Wait for connect before continuing
        conn_timeout = 5
        while not self.ws.sock or not self.ws.sock.connected and conn_timeout:
            sleep(1)
            conn_timeout -= 1
        if not conn_timeout:
            self.logger.error("Couldn't connect to WS! Exiting.")
            self.exit()
            raise websocket.WebSocketTimeoutException('Couldn\'t connect to WS! Exiting.') 
开发者ID:5ymph0en1x,项目名称:SyBrain,代码行数:27,代码来源:bitmex_websocket_com.py

示例11: _websocket_exc_handler

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def _websocket_exc_handler(method):
        def wrapper(self, *args, **kwds):
            try:
                return method(self, *args, **kwds)
            except (TimeoutError, websocket.WebSocketTimeoutException):
                self.logger.warning("Websocket timeout")
            except (ConnectionError, websocket.WebSocketException) as e:
                # If we lose the connection we must reinitialize our state
                self.logger.error(str(e))
                self._reset_state()
            except Exception as e:
                self.logger.exception("Websocket callback unhandled exception")
                self._reset_state()

        return wrapper 
开发者ID:Parrot-Developers,项目名称:olympe,代码行数:17,代码来源:media.py

示例12: catch_websocket_connection_errors

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def catch_websocket_connection_errors():
  """A context manager that translates websocket errors into ConnectionError."""
  try:
    yield
  except websocket.WebSocketConnectionClosedException:
    raise ConnectionError("Connection already closed. SC2 probably crashed. "
                          "Check the error log.")
  except websocket.WebSocketTimeoutException:
    raise ConnectionError("Websocket timed out.")
  except socket.error as e:
    raise ConnectionError("Socket error: %s" % e) 
开发者ID:deepmind,项目名称:pysc2,代码行数:13,代码来源:protocol.py

示例13: start

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def start(self):
        """
        Start the websocket client threads
        :return:
        """
        super(BitfinexWSS, self).start()

        log.info("BitfinexWSS.start(): Initializing Websocket connection..")
        while self.conn is None:
            try:
                self.conn = create_connection(self.addr, timeout=10)
            except WebSocketTimeoutException:
                self.conn = None
                print("Couldn't create websocket connection - retrying!")

        log.info("BitfinexWSS.start(): Initializing receiver thread..")
        if not self.receiver_thread:
            self.receiver_thread = Thread(target=self.receive, name='Receiver Thread')
            self.receiver_thread.start()
        else:
            log.info("BitfinexWSS.start(): Thread not started! "
                     "self.receiver_thread is populated!")

        log.info("BitfinexWSS.start(): Initializing processing thread..")
        if not self.processing_thread:
            self.processing_thread = Thread(target=self.process, name='Processing Thread')
            self.processing_thread.start()
        else:
            log.info("BitfinexWSS.start(): Thread not started! "
                     "self.processing_thread is populated!")

        self.setup_subscriptions() 
开发者ID:Crypto-toolbox,项目名称:bitex,代码行数:34,代码来源:bitfinex.py

示例14: receive

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def receive(self):
        """
        Receives incoming websocket messages, and puts them on the Client queue
        for processing.
        :return:
        """
        while self.running:
            if self._receiver_lock.acquire(blocking=False):
                try:
                    raw = self.conn.recv()
                except WebSocketTimeoutException:
                    self._receiver_lock.release()
                    continue
                except WebSocketConnectionClosedException:
                    # this needs to restart the client, while keeping track
                    # of the currently subscribed channels!
                    self.conn = None
                    self._controller_q.put('restart')
                except AttributeError:
                    # self.conn is None, idle loop until shutdown of thread
                    self._receiver_lock.release()
                    continue
                msg = time.time(), json.loads(raw)
                log.debug("receiver Thread: Data Received: %s", msg)
                self.receiver_q.put(msg)
                self._receiver_lock.release()
            else:
                # The receiver_lock was locked, idling until available
                time.sleep(0.5) 
开发者ID:Crypto-toolbox,项目名称:bitex,代码行数:31,代码来源:bitfinex.py

示例15: _process_data

# 需要导入模块: import websocket [as 别名]
# 或者: from websocket import WebSocketTimeoutException [as 别名]
def _process_data(self):
        self.conn = create_connection(self.addr, timeout=4)
        payload = json.dumps({'type': 'subscribe', 'product_ids': self.pairs})
        self.conn.send(payload)
        while self.running:
            try:
                data = json.loads(self.conn.recv())
            except (WebSocketTimeoutException, ConnectionResetError):
                self._controller_q.put('restart')

            if 'product_id' in data:
                self.data_q.put(('order_book', data['product_id'],
                                 data, time.time()))
        self.conn = None 
开发者ID:Crypto-toolbox,项目名称:bitex,代码行数:16,代码来源:gdax.py


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