当前位置: 首页>>代码示例>>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;未经允许,请勿转载。