Efficiently send large arrays across machines
MIT License
Efficiently send large arrays across machines.
Teleport provides a Server
that you can bind functions to and a Client
that
can call the functions and receive their results. The function arguments and
return values are both trees of Numpy arrays. The data is sent efficiently
without serialization to maximize throughput.
pip install git+https://github.com/danijar/teleport.git
This example runs the server and client in the same Python program using subprocesses, but they could also be separate Python scripts running on different machines.
def server():
import teleport
server = teleport.Server('tcp://*:2222')
server.bind('add', lambda data: {'result': data['foo'] + data['bar']})
server.bind('msg', lambda data: print('Message from client:', data['msg']))
server.run()
def client():
import teleport
client = teleport.Client('tcp://localhost:2222')
client.connect()
future = client.add({'foo': 1, 'bar': 1})
result = future.result()
print(result) # {'result': 2}
client.msg({'msg': 'Hello World'})
if __name__ == '__main__':
import teleport
server_proc = teleport.Process(server, start=True)
client_proc = teleport.Process(client, start=True)
client_proc.join()
server_proc.terminate()
Several productivity and performance features are available:
Future
objects. The maximum number offuture.result()
or, if the user did not store theserver.check()
.Thread
and Process
implementations with exceptionProcServer
behaves just like the normalServer
but uses a background process to batch requests and fan out results,If you have a question, please file an issue.