mbr / tinyrpc

A compact, modular transport and protocol agnostic RPC library. Does jsonrpc v2.
https://tinyrpc.readthedocs.org
MIT License
156 stars 53 forks source link

Add experimental asyncio support #55

Closed dangusev closed 6 years ago

dangusev commented 6 years ago

@lnoor , so, there's an example of async Dispatcher, Server and Client. Please take a look.

dangusev commented 6 years ago

Hi, that's what I was talking about before. AsyncTransport class itself is useless and just will not work without AsyncServer/AsyncClient because asyncio force you to use async def-context everywhere, where you want to call asynchronous code with await statement. E.g. you can't call await method() from synchronous version of _dispatch(), like you can do with gevent code. You will still need to override every peace of code which use it somehow (client, server, dispatcher).

I totally understand, that you probably don't want to add this code in tinyrpc. In this case, I might create an "async" version (aiotinyrpc e.g.) as a separate library with tinyrpc as a dependency.

lnoor commented 6 years ago

Get that now. Off course you are free to create a fork of tinyrpc. But I rather try to join forces.

I've tried to read up on asyncio, 'cause your sample does look really nice. It appears that to maximize asyncio you should also modify the transport, perhaps use aiohttp for it, and also the protocol. Which means that in order to support asyncio you have to touch all of tinyrpc and also bump the minimum version of Python to 3.5.

I've tried to find some stats on the relative use of Python3 vs. Python2 but couldn't find any recent ones. I do know that at my job I need to work with both P2 and P3 and I don't want to maintain two codebases. Yet I hope P2 will die off one day and asyncio could be set to become the predominant event loop framework that needs to be supported. Also, I'm planning a version 1.0 which will be incompatible with the current version to be released later this year.

So, all in all, I want to propose this:

I want to be closely involved in the refactoring but most of the asyncio work, the tests and documentation would need to come from you. It would be more work and take more time so: are you interested in taking that on?

dangusev commented 6 years ago

Ok, I'm ready to put some efforts in it. Could you create a branch for it? I don't get how to create a branch in a upstream repo from the forked one)

I really like current design in general, that's why I choose this library) I don't think that we should make such many changes. The biggest part would be tests and. Perhaps, I would put respond_error logic to the Protocol layer from the Request docs, I suppose.

Anyway, I'll take a look how can we change the code to make it even more pluggable and we'll discuss it.

lnoor commented 6 years ago

Great! Looking forward to work with you. I set things up and get in touch with you per email.