def create_connection(service, address=('127.0.0.1', 6000), *,
protocol_cls=TBinaryProtocol, timeout=None, loop=None, **kw):
"""Create a thrift connection.
This function is a :ref:`coroutine <coroutine>`.
Open a connection to the thrift server by address argument.
:param service: a thrift service object
:param address: a (host, port) tuple
:param protocol_cls: protocol type, default is :class:`TBinaryProtocol`
:param timeout: if specified, would raise `asyncio.TimeoutError` if one rpc call is longer than `timeout`
:param loop: :class:`Eventloop <asyncio.AbstractEventLoop>` instance, if not specified, default loop is used.
:param kw: params relaied to asyncio.open_connection()
:return: newly created :class:`ThriftConnection` instance.
"""
host, port = address
reader, writer = yield from asyncio.open_connection(
host, port, loop=loop, **kw)
iprotocol = protocol_cls(reader)
oprotocol = protocol_cls(writer)
return ThriftConnection(service, iprot=iprotocol, oprot=oprotocol,
address=address, loop=loop, timeout=timeout)
评论列表
文章目录