Thriftpy / thriftpy

Thriftpy has been deprecated, please migrate to https://github.com/Thriftpy/thriftpy2
MIT License
1.15k stars 286 forks source link

Fully Asyncio Support #308

Open ethe opened 7 years ago

ethe commented 7 years ago

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 commented 6 years ago

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

ethe commented 6 years ago

@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).

HIRANO-Satoshi commented 6 years ago

@hit9 Could you merge this PR?

hit9 commented 6 years ago

Sorry but I am removed from this organization.

1533624849161