thriftpy icon indicating copy to clipboard operation
thriftpy copied to clipboard

Fully Asyncio Support

Open ethe opened this issue 7 years ago • 4 comments

I find #246 this issue so I wrote an asyncio support for thriftpy, and it can pass all the original test cases. Now you can use thriftpy like this:

######
# This is a thrift client
######
import thriftpy
import asyncio
from thriftpy.rpc import make_aio_client


echo_thrift = thriftpy.load("echo.thrift", module_name="echo_thrift")


async def request():
    client = await make_aio_client(
        echo_thrift.EchoService, '127.0.0.1', 6000)
    print(await client.echo('hello, world'))
    client.close()
######
# This is a thrift server
######
import asyncio
import thriftpy

from thriftpy.rpc import make_aio_server

echo_thrift = thriftpy.load("echo.thrift", module_name="echo_thrift")


class Dispatcher(object):
    async def echo(self, param):
        print(param)
        await asyncio.sleep(0.1)
        return param


def main():
    server = make_aio_server(
        echo_thrift.EchoService, Dispatcher(), '127.0.0.1', 6000)
    server.serve()


if __name__ == '__main__':
    main()

ethe avatar Sep 03 '17 09:09 ethe

Yeah I think it can be merged smoothly, I just resolved the last little conflict.

ethe avatar Jul 20 '18 06:07 ethe

@wooparadog The different between two pull requests is they realized different transport (I support bufferd and #299 supports memory bufferd). In my opinion, the buffered transport realization is more difficult than framed transport on this feature. And I also find that there are some blocking I/O at the low level not be yielded out in #299 realization (read_frame, etc.), cause it still used blocking socket, and this pull request is fully non-blocking (based on non-blocking stream reader and writer).

ethe avatar Jul 20 '18 06:07 ethe

@hit9 Could you merge this PR?

HIRANO-Satoshi avatar Aug 07 '18 06:08 HIRANO-Satoshi

Sorry but I am removed from this organization.

1533624849161

hit9 avatar Aug 07 '18 06:08 hit9