| 1 | import json |
| 2 | |
| 3 | class RPCProxy: |
| 4 | def __init__(self, connection): |
| 5 | self._connection = connection |
| 6 | def __getattr__(self, name): |
| 7 | def do_rpc(*args, **kwargs): |
| 8 | self._connection.send(json.dumps((name, args, kwargs))) |
| 9 | result = json.loads(self._connection.recv()) |
| 10 | return result |
| 11 | return do_rpc |
| 12 | |
| 13 | # Example use |
| 14 | from multiprocessing.connection import Client |