Skip to content

About

Asyncio-native fork of RPyC for reliable and efficient asynchronous inter-process calls

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Build Status Python Versions License: MIT

rpyc-async

rpyc-async is an asyncio-native fork of RPyC (Remote Python Call), a transparent library for symmetrical remote procedure calls, clustering, and distributed-computing. RPyC makes use of object-proxying, a technique that employs python's dynamic nature, to overcome the physical boundaries between processes and computers, so that remote objects can be manipulated as if they were local.

This fork adds native async/await support: async services, async clients, and bidirectional async callbacks driven by a persistent event loop.

Warning

rpyc-async is not a drop-in replacement for classic synchronous RPyC. It is a separate distribution with its own version line, built around async_connect() and AsyncioServer. Compatibility with upstream RPyC is not guaranteed, at neither the API nor the wire-protocol level. Both peers must run rpyc-async.

Relationship to upstream RPyC

Upstream project RPyC by Tomer Filiba and contributors
Forked at RPyC 6.0.1
This fork rpyc-async 1.1.0 (versioned independently)
Distribution name rpyc-async
Import name rpyc_async (see note below)
Licence MIT (both upstream and this fork)

The upstream commit history is preserved in this repository, so authorship and provenance of the original RPyC code remain visible in git log. See LICENSE and CONTRIBUTORS for attribution.

Installation

pip install rpyc-async

Requires Python 3.10+. The fork's import name is rpyc_async, while upstream RPyC still uses rpyc — the two distributions can be installed side by side in the same environment. If you only need the classic synchronous API, install upstream RPyC (pip install rpyc); if you need the asyncio-native API, install this fork (pip install rpyc-async).

Existing code written for upstream can keep the shorter rpyc. spelling by aliasing the import at the top of each module:

import rpyc_async as rpyc

All examples in this README use that alias.

Platform Support

Warning

Windows is currently not supported. The asyncio-native machinery (async_connect / AsyncioServer) is built on event-driven file-descriptor readiness (loop.add_reader), which the default Windows event loop (ProactorEventLoop) does not implement; the legacy Windows pipe transport additionally requires the third-party pywin32 package and is known to be unreliable.

The current release (1.1.0) has been tested only on Linux (CPython 3.10-3.14). There is no CI coverage for Windows or macOS.

Server Selection Guide

rpyc-async provides two main server implementations. Choose based on your async requirements:

Server Type Use When Limitations
ThreadedServer
  • Synchronous methods
  • Unidirectional async (client→server only)
  • Simple use cases
  • Cannot support bidirectional async (async callbacks)
  • Async methods without persistent event loop will raise error
AsyncioServer
  • Bidirectional async
  • Async callbacks
  • Server calling client async methods
  • Requires asyncio event loop
  • More complex setup

Quick Examples

ThreadedServer (for simple sync/unidirectional async):

from rpyc_async import ThreadedServer, Service

class MyService(Service):
    def exposed_sync_method(self, x):
        return x * 2

server = ThreadedServer(MyService, port=18861)
server.start()

AsyncioServer (for bidirectional async with callbacks):

from rpyc_async import AsyncioServer, Service
import asyncio

class MyService(Service):
    async def exposed_async_with_callback(self, callback, value):
        # Server can call client's async callback
        result = await callback(value * 2)
        return f"Got: {result}"

async def main():
    server = AsyncioServer(MyService, port=18861)
    await server.start()
    # Server runs in background, handle other tasks
    await asyncio.sleep(3600)  # or other async work

asyncio.run(main())

Client for AsyncioServer — use await rpyc.async_connect(...), NOT rpyc.connect():

import rpyc_async as rpyc
import asyncio

async def main():
    conn = await rpyc.async_connect("localhost", 18861)
    try:
        # Native async method — just await.
        result = await conn.root.some_async_method(42)
        # Sync remote method? Wrap with rpyc.async_() to stay event-driven.
        # Keep the wrapper in a variable: it is cached behind a weak ref.
        a_sync = rpyc.async_(conn.root.some_sync_method)
        sync_result = await a_sync(42)
    finally:
        await conn.aclose()   # not conn.close() — that blocks the loop

asyncio.run(main())

rpyc.connect() is synchronous — it blocks socket.connect and every later sync_request on the calling thread. From inside an asyncio event loop it now raises RuntimeError pointing at rpyc.async_connect. See docs/DESIGN_ASYNC_CONNECT_POLICY.md.

For more details on async support, see docs/LIMITATIONS.md.

Note

NO POLLING POLICY (AsyncioServer). The asyncio server and the asyncio-serving code path inside Connection must never poll via while not conn.closed: await asyncio.sleep(x). The old 100 ms poll burned ~33% CPU with just two active connections. Use event-driven primitives instead: await conn.wait_closed(), conn.add_close_callback(cb), asyncio.Event, or loop.add_reader(fd, cb). See docs/ASYNCIO_SERVER_MIGRATION.md for the full policy and tests/test_no_polling_policy.py for enforcement.

https://raw.githubusercontent.com/rr-develop/rpyc_async/main/docs/_static/screenshot.png

A screenshot of a remote client connecting to a server.

Note that text written to the server's stdout is actually printed on the server's console.

Documentation

Documentation for classic synchronous RPyC lives at https://rpyc.readthedocs.io

About

Asyncio-native fork of RPyC for reliable and efficient asynchronous inter-process calls

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages