rpc
RPC
XMLRPC
- 동시에 여러 커넥션 처리(threading)
from socketserver import ThreadingMixIn class ThreadedXMLRPCServer(ThreadingMixIn, SimpleXMLRPCServer): pass class RequestHandler(SimpleXMLRPCRequestHandler): rpc_paths = ('/RPC2',) with ThreadedXMLRPCServer((ip_address, port), requestHandler=RequestHandler, allow_none=True, logRequests=False) as server: server.register_introspection_functions() def ping(): return 'pong' server.register_function(ping, 'ping') server.serve_forever()
msgpack-rpc
설치
pip install msgpack-rpc-python pip install msgpack-numpy
server
import msgpack import msgpack_numpy as m m.patch() import numpy as np import msgpackrpc class SumServer(object): def sum(self, x, y): return x + y server = msgpackrpc.Server(SumServer()) server.listen(msgpackrpc.Address("localhost", 18800)) server.start()
client
import msgpack import msgpack_numpy as m m.patch() import numpy as np import msgpackrpc client = msgpackrpc.Client(msgpackrpc.Address("localhost", 18800)) result = client.call('sum', 1, 2) # = > 3 result = client.call('sum', np.arange(10), np.arange(10, 20))
zerorpc
rpc.txt · 마지막으로 수정됨: 2024/03/23 02:38 저자 127.0.0.1