Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to implement an async version #37

Open
tcalmant opened this issue Nov 17, 2018 · 5 comments
Open

Try to implement an async version #37

tcalmant opened this issue Nov 17, 2018 · 5 comments
Assignees
Milestone

Comments

@tcalmant
Copy link
Owner

It would be interesting to implement an asyncio-based version of the library, as it undeniably increases performances in most I/O cases.

This would require a big refactoring of the project, in order to share as most code as possible between the sync & async versions of the transport and protocol layers.

It is necessary to decide if the project will depend on a third-party library to handle this or if it will use the Python 3.4+ API & syntax.
Note: the library has to stay compatible with Python 2 (at least for some years), which means all of the Python 3 syntax would be in a specific module, loaded when possible.

You can vote for or against this proposal.

@tcalmant tcalmant changed the title Try to implement an asyncio version Try to implement an async version Nov 17, 2018
@tcalmant tcalmant self-assigned this Feb 15, 2019
@tcalmant tcalmant added this to the 0.5.0 milestone Feb 15, 2019
@tcalmant
Copy link
Owner Author

tcalmant commented Feb 15, 2019

First try to implement an asyncio server is a success, using aiohttp as the underlying HTTP server.

Here are the tasks to implement the asynchronous server:

  • Extract the JSON-RPC handling / method calls from the HTTP(s)-handling part. There will be 2 versions of this: one synchronous, one asynchronous (reserved to Python 3.5+).
  • Prepare a request handler for aiohttp based on that asynchronous JSON-RPC handler

For an asynchronous client:

  • Check if inheriting the ServerProxy class from XML-RPC is still the way to go
  • Mimic ServerProxy API with an aiohttp client
  • Implement current features of ServerProxy in the asynchronous version

@tcalmant
Copy link
Owner Author

The first version of the asynchronous request handler has been pushed on the protocol_extract branch.

A draft of documentation have also been pushed, with a snippet to start the server with aiohttp.

@tcalmant
Copy link
Owner Author

tcalmant commented Mar 3, 2019

And I finally found the time to make an aiohttp version of ServerProxy (called AsyncServerProxy).
It is available on the protocol_extract branch.

The usage is pretty straightforward: you just need to use await in front of all calls to the server.

The dependency on aiohttp is somehow limited, as I mimic the Transport model of the xmlrpclib model. Maybe I'll put the aiohttp specific code in another module in order to avoid a hard dependency on this library.

Documentation and unit tests are still to be written. Please comment with to this issue if you try the asynchronous mode and find good or bad.

@tcalmant
Copy link
Owner Author

tcalmant commented Mar 8, 2019

Protocol unit tests from the synchronous client and server are now also applied on their asynchronous versions.

Next steps will be:

  • add tests for the special features of jsonrpclib (extra headers, ...)
  • move the aiohttp specific parts to a sub-package, to allow implementations based on other libraries without requiring the installation of aiohttp
  • provide an implementation of the aiohttp-based server in said sub-package (currently only available in the tests)

@tcalmant
Copy link
Owner Author

tcalmant commented Mar 9, 2019

aiohttp specific code has been moved to a new impl subpackage. It should now be possible to create a new provider with another library (I don't know a lot of equivalents).

I've also added some type hints and potentially fixed a bug in the class converter (when copying the LocalClasses dictionary)

Documentation is still a draft, available as the protocol_extract version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant