Skip to content

Instantly share code, notes, and snippets.

@Averroes
Created April 10, 2015 17:14
Show Gist options
  • Select an option

  • Save Averroes/bfdaf9b0c596746ca3c2 to your computer and use it in GitHub Desktop.

Select an option

Save Averroes/bfdaf9b0c596746ca3c2 to your computer and use it in GitHub Desktop.
implementing remote procedure call
import json
class RPCProxy:
def __init__(self, connection):
self._connection = connection
def __getattr__(self, name):
def do_rpc(*args, **kwargs):
self._connection.send(json.dumps((name, args, kwargs)))
result = json.loads(self._connection.recv())
return result
return do_rpc
# Example use
from multiprocessing.connection import Client
c = Client(('localhost', 17000), authkey=b'peekaboo')
proxy = RPCProxy(c)
print(proxy.add(2, 3))
print(proxy.sub(2, 3))
try:
print(proxy.sub([1, 2], 4))
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment