thriftpy
thriftpy copied to clipboard
Fully Asyncio Support
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()
Yeah I think it can be merged smoothly, I just resolved the last little conflict.
@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).
@hit9 Could you merge this PR?
Sorry but I am removed from this organization.