本文整理汇总了Python中thrift.Thrift.TApplicationException方法的典型用法代码示例。如果您正苦于以下问题:Python Thrift.TApplicationException方法的具体用法?Python Thrift.TApplicationException怎么用?Python Thrift.TApplicationException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类thrift.Thrift
的用法示例。
在下文中一共展示了Thrift.TApplicationException方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: execute
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [as 别名]
def execute(self, *args, **kwargs):
if not self.params:
raise ExecuteActionError("is empty")
host = self.params.get("host", "127.0.0.1")
port = int(self.params.get("port", 5643))
max_connections = int(self.params.get("max_connections", config.get("ACTION_THRIFT_MAX_CONNECTIONS", 64)))
try:
client = self.get_client(host, port, max_connections)
try:
yield client.forsun_call(self.plan.key, int(self.ts), self.params)
except TApplicationException as e:
logging.error("thrift action execute error '%s' %s:%s '%s' %.2fms", self.plan.key, host, port, e,
(time.time() - self.start_time) * 1000)
else:
logging.debug("thrift action execute '%s' %s:%s %.2fms", self.plan.key, host, port,
(time.time() - self.start_time) * 1000)
except Exception as e:
logging.error("thrift action execute error '%s' %s:%s '%s' %.2fms", self.plan.key, host, port, e,
(time.time() - self.start_time) * 1000)
raise ActionExecuteRetry()
示例2: default_thrift_client_replace_if
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [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
示例3: method_other_error
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [as 别名]
def method_other_error(self):
raise TApplicationException()
示例4: test_other_error
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [as 别名]
def test_other_error(self):
client = FakeThriftClientMixin(HostsProvider(HOSTS))
self.assertRaises(TApplicationException, client.method_other_error)
# Connection should be established.
self.assertEqual('fakehost1', client.host)
self.assertEqual(100, client.port)
self.assertTrue(client.connected)
# requests_served doesn't not increase.
self.assertEqual(0, client.requests_served)
示例5: test_replace_if
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [as 别名]
def test_replace_if(self):
def replace_if(ex):
return isinstance(ex, ThriftConnectionError)
client = FakePooledThriftClientMixin(host_provider=HostsProvider(HOSTS),
conn_replace_policy=replace_if)
self.assertRaises(ThriftConnectionError, client.method_network_error)
self.assertEqual(0, client.client_pool.num_connected)
self.assertRaises(TApplicationException, client.method_other_error)
self.assertEqual(1, client.client_pool.num_connected)
示例6: _issueLiffView
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [as 别名]
def _issueLiffView(self, ctx, request):
memory_buffer = TMemoryOutputBuffer(self._transport.get_request_size_limit())
oprot = self._protocol_factory.get_protocol(memory_buffer)
oprot.write_request_headers(ctx)
oprot.writeMessageBegin('issueLiffView', TMessageType.CALL, 0)
args = issueLiffView_args()
args.request = request
args.write(oprot)
oprot.writeMessageEnd()
response_transport = await self._transport.request(ctx, memory_buffer.getvalue())
iprot = self._protocol_factory.get_protocol(response_transport)
iprot.read_response_headers(ctx)
_, mtype, _ = iprot.readMessageBegin()
if mtype == TMessageType.EXCEPTION:
x = TApplicationException()
x.read(iprot)
iprot.readMessageEnd()
if x.type == TApplicationExceptionType.RESPONSE_TOO_LARGE:
raise TTransportException(type=TTransportExceptionType.RESPONSE_TOO_LARGE, message=x.message)
raise x
result = issueLiffView_result()
result.read(iprot)
iprot.readMessageEnd()
if result.e is not None:
raise result.e
if result.success is not None:
return result.success
raise TApplicationException(TApplicationExceptionType.MISSING_RESULT, "issueLiffView failed: unknown result")
示例7: _revokeToken
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [as 别名]
def _revokeToken(self, ctx, request):
memory_buffer = TMemoryOutputBuffer(self._transport.get_request_size_limit())
oprot = self._protocol_factory.get_protocol(memory_buffer)
oprot.write_request_headers(ctx)
oprot.writeMessageBegin('revokeToken', TMessageType.CALL, 0)
args = revokeToken_args()
args.request = request
args.write(oprot)
oprot.writeMessageEnd()
response_transport = await self._transport.request(ctx, memory_buffer.getvalue())
iprot = self._protocol_factory.get_protocol(response_transport)
iprot.read_response_headers(ctx)
_, mtype, _ = iprot.readMessageBegin()
if mtype == TMessageType.EXCEPTION:
x = TApplicationException()
x.read(iprot)
iprot.readMessageEnd()
if x.type == TApplicationExceptionType.RESPONSE_TOO_LARGE:
raise TTransportException(type=TTransportExceptionType.RESPONSE_TOO_LARGE, message=x.message)
raise x
result = revokeToken_result()
result.read(iprot)
iprot.readMessageEnd()
if result.e is not None:
raise result.e
示例8: process
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [as 别名]
def process(self, ctx, iprot, oprot):
args = issueLiffView_args()
args.read(iprot)
iprot.readMessageEnd()
result = issueLiffView_result()
try:
ret = self._handler([ctx, args.request])
if inspect.iscoroutine(ret):
ret = await ret
result.success = ret
except TApplicationException as ex:
async with self._lock:
_write_application_exception(ctx, oprot, "issueLiffView", exception=ex)
return
except LiffException as e:
result.e = e
except Exception as e:
async with self._lock:
_write_application_exception(ctx, oprot, "issueLiffView", ex_code=TApplicationExceptionType.INTERNAL_ERROR, message=str(e))
raise
async with self._lock:
try:
oprot.write_response_headers(ctx)
oprot.writeMessageBegin('issueLiffView', TMessageType.REPLY, 0)
result.write(oprot)
oprot.writeMessageEnd()
oprot.get_transport().flush()
except TTransportException as e:
# catch a request too large error because the TMemoryOutputBuffer always throws that if too much data is written
if e.type == TTransportExceptionType.REQUEST_TOO_LARGE:
raise _write_application_exception(ctx, oprot, "issueLiffView", ex_code=TApplicationExceptionType.RESPONSE_TOO_LARGE, message=e.message)
else:
raise e
示例9: _write_application_exception
# 需要导入模块: from thrift import Thrift [as 别名]
# 或者: from thrift.Thrift import TApplicationException [as 别名]
def _write_application_exception(ctx, oprot, method, ex_code=None, message=None, exception=None):
if exception is not None:
x = exception
else:
x = TApplicationException(type=ex_code, message=message)
oprot.write_response_headers(ctx)
oprot.writeMessageBegin(method, TMessageType.EXCEPTION, 0)
x.write(oprot)
oprot.writeMessageEnd()
oprot.get_transport().flush()
return x