當前位置: 首頁>>代碼示例>>Python>>正文


Python Thrift.TException方法代碼示例

本文整理匯總了Python中thrift.Thrift.TException方法的典型用法代碼示例。如果您正苦於以下問題:Python Thrift.TException方法的具體用法?Python Thrift.TException怎麽用?Python Thrift.TException使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在thrift.Thrift的用法示例。


在下文中一共展示了Thrift.TException方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: process

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def process(self, iprot, oprot):
    (name, type, seqid) = iprot.readMessageBegin();
    if type != TMessageType.CALL & type != TMessageType.ONEWAY:
      raise TException("TMultiplex protocol only supports CALL & ONEWAY")

    index = name.find(TMultiplexedProtocol.SEPARATOR)
    if index < 0:
      raise TException("Service name not found in message name: " + name + ". Did you forget to use TMultiplexProtocol in your client?")

    serviceName = name[0:index]
    call = name[index+len(TMultiplexedProtocol.SEPARATOR):]
    if not serviceName in self.services:
      raise TException("Service name not found: " + serviceName + ". Did you forget to call registerProcessor()?")

    standardMessage = (
      call,
      type,
      seqid
    )
    return self.services[serviceName].process(StoredMessageProtocol(iprot, standardMessage), oprot) 
開發者ID:XiaoMi,項目名稱:galaxy-sdk-python,代碼行數:22,代碼來源:TMultiplexedProcessor.py

示例2: open

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def open(self):
        """Establish HTTP connection to the server.

        Note: THttpClient also supports https and will use http/https according
        to the scheme in the URL it is given.
        """
        self._lock.acquire()
        try:
            self._transport = THttpClient.THttpClient(self._collector_url)
            self._transport.open()
            protocol = TBinaryProtocol.TBinaryProtocol(self._transport)
            self._client = ReportingService.Client(protocol)
        except Thrift.TException:
            self._open_exceptions_count += 1
        else:
            self.ready = True
        finally:
            self._lock.release()


    # May throw an Exception on failure. 
開發者ID:lightstep,項目名稱:lightstep-tracer-python,代碼行數:23,代碼來源:thrift_connection.py

示例3: process

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def process(self, iprot, oprot):
        (name, type, seqid) = iprot.readMessageBegin()
        if type != TMessageType.CALL and type != TMessageType.ONEWAY:
            raise TException("TMultiplex protocol only supports CALL & ONEWAY")

        index = name.find(TMultiplexedProtocol.SEPARATOR)
        if index < 0:
            raise TException("Service name not found in message name: " + name + ". Did you forget to use TMultiplexProtocol in your client?")

        serviceName = name[0:index]
        call = name[index + len(TMultiplexedProtocol.SEPARATOR):]
        if serviceName not in self.services:
            raise TException("Service name not found: " + serviceName + ". Did you forget to call registerProcessor()?")

        standardMessage = (call, type, seqid)
        return self.services[serviceName].process(StoredMessageProtocol(iprot, standardMessage), oprot) 
開發者ID:Aditmadzs,項目名稱:Protect4,代碼行數:18,代碼來源:TMultiplexedProcessor.py

示例4: report

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def report(self, *args, **kwargs):
        """Report to the server."""
        # Notice the annoying case change on the method name. I chose to stay
        # consistent with casing in this class vs staying consistent with the
        # casing of the pass-through method.
        resp = None
        with self._lock:
            try:
                if self._client:
                    headers = {"Lightstep-Access-Token": args[0].access_token}
                    self._transport.setCustomHeaders(headers)
                    resp = self._client.Report(*args, **kwargs)
                    self._report_consecutive_errors = 0
            except Thrift.TException:
                self._report_consecutive_errors += 1
                self._report_exceptions_count += 1
                raise Exception('Thrift exception')
            except EOFError:
                self._report_consecutive_errors += 1
                self._report_eof_count += 1
                raise Exception('EOFError')
            finally:
                # In case the Thrift client has fallen into an unrecoverable state,
                # recreate the Thrift data structure if there are continued report
                # failures
                if self._report_consecutive_errors == CONSECUTIVE_ERRORS_BEFORE_RECONNECT:
                    self._report_consecutive_errors = 0
                    self.ready = False

        return resp 
開發者ID:lightstep,項目名稱:lightstep-tracer-python,代碼行數:32,代碼來源:thrift_connection.py

示例5: perform_request

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def perform_request(self, method, url, params=None, body=None, timeout=None, ignore=()):
        request = RestRequest(method=Method._NAMES_TO_VALUES[method.upper()], uri=url,
                    parameters=params, body=body)

        start = time.time()
        tclient = None
        try:
            tclient = self._get_connection()
            response = tclient.execute(request)
            duration = time.time() - start
        except SocketTimeout as e:
            self.log_request_fail(method, url, body, time.time() - start, exception=e)
            raise ConnectionTimeout('TIMEOUT', str(e), e)
        except (TException, SocketTimeout) as e:
            self.log_request_fail(method, url, body, time.time() - start, exception=e)
            if tclient:
                try:
                    # try closing transport socket
                    tclient.transport.close()
                except Exception as e:
                    logger.warning(
                        'Exception %s occured when closing a failed thrift connection.',
                        e, exc_info=True
                    )
            raise ConnectionError('N/A', str(e), e)

        self._release_connection(tclient)

        if not (200 <= response.status < 300) and response.status not in ignore:
            self.log_request_fail(method, url, body, duration, response.status)
            self._raise_error(response.status, response.body)

        self.log_request_success(method, url, url, body, response.status,
            response.body, duration)

        headers = {}
        if response.headers:
            headers = dict((k.lower(), v) for k, v in response.headers.items())
        return response.status, headers, response.body or '' 
開發者ID:hvandenb,項目名稱:splunk-elasticsearch,代碼行數:41,代碼來源:thrift.py

示例6: perform_request

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def perform_request(self, method, url, params=None, body=None, timeout=None, ignore=()):
        request = RestRequest(method=Method._NAMES_TO_VALUES[method.upper()], uri=url,
                    parameters=params, body=body)

        start = time.time()
        tclient = None
        try:
            tclient = self._get_connection()
            response = tclient.execute(request)
            duration = time.time() - start
        except SocketTimeout as e:
            self.log_request_fail(method, url, body, time.time() - start, exception=e)
            raise ConnectionTimeout('TIMEOUT', str(e), e)
        except (TException, SocketError) as e:
            self.log_request_fail(method, url, body, time.time() - start, exception=e)
            if tclient:
                try:
                    # try closing transport socket
                    tclient.transport.close()
                except Exception as e:
                    logger.warning(
                        'Exception %s occured when closing a failed thrift connection.',
                        e, exc_info=True
                    )
            raise ConnectionError('N/A', str(e), e)

        self._release_connection(tclient)

        if not (200 <= response.status < 300) and response.status not in ignore:
            self.log_request_fail(method, url, body, duration, response.status)
            self._raise_error(response.status, response.body)

        self.log_request_success(method, url, url, body, response.status,
            response.body, duration)

        headers = {}
        if response.headers:
            headers = dict((k.lower(), v) for k, v in response.headers.items())
        return response.status, headers, response.body or '' 
開發者ID:KunihikoKido,項目名稱:sublime-elasticsearch-client,代碼行數:41,代碼來源:thrift.py

示例7: default_thrift_client_replace_if

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def default_thrift_client_replace_if(exception):
    """Default policy on whether to replace the underlying thrift client.

    The default policy tests whether the given exception is a user defined
    thrift exception. If the given exception is a user defined thrift exception,
    it indicates the underlying connection to the thrift server is sound and can
    continue to be used.

    Args:
        exception: Exception thrown from method invocation of the thrift client.

    Return:
        True, if the underlying thrift client needs to be replaced; otherwise,
        False will be returned.

    """
    # NOTE: this is the best I can come up with to exam whether the given
    # exception is a user defined exception or not. Currently
    # TApplicationException, TProtocolException, TTransportException, and user
    # defined thrift exceptions are all subclasses of TException; however, the
    # other types of exceptions besides user defined ones don't have thrift_spec
    # attribute
    if isinstance(exception, TException):
        if (isinstance(exception, TApplicationException) or
                hasattr(exception, 'thrift_spec')):
            return False
    return True 
開發者ID:pinterest,項目名稱:kingpin,代碼行數:29,代碼來源:thrift_client_mixin.py

示例8: __init__

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def __init__(self, host, port):
        try:
            # Make socket
            transport = TSocket.TSocket(host=host, port=port)
            # Buffering is critical. Raw sockets are very slow
            transport = TTransport.TBufferedTransport(transport)
            # Wrap in a protocol
            protocol = TBinaryProtocol.TBinaryProtocol(transport)
            self.remote_controller = RemoteController.Client(protocol)
            # Connect!
            transport.open()
        except Thrift.TException as tx:
            self.logger.warn('%s' % tx.message) 
開發者ID:hazelcast,項目名稱:hazelcast-python-client,代碼行數:15,代碼來源:client.py

示例9: testException

# 需要導入模塊: from thrift import Thrift [as 別名]
# 或者: from thrift.Thrift import TException [as 別名]
def testException(self, arg):
        """
        Print 'testException(%s)' with arg as '%s'
        @param string arg - a string indication what type of exception to throw
        if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
        elsen if arg == "TException" throw TException
        else do not throw anything

        Parameters:
         - arg

        """
        pass 
開發者ID:uber,項目名稱:tchannel-python,代碼行數:15,代碼來源:ThriftTest.py


注:本文中的thrift.Thrift.TException方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。