From e6809397a39135acfbfce4d1a86e17dbfc61c165 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Thu, 24 Mar 2016 00:49:02 +0800 Subject: [PATCH] protocols: add remote_exec --- artiq/protocols/remote_exec.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 artiq/protocols/remote_exec.py diff --git a/artiq/protocols/remote_exec.py b/artiq/protocols/remote_exec.py new file mode 100644 index 000000000..621e97b8b --- /dev/null +++ b/artiq/protocols/remote_exec.py @@ -0,0 +1,34 @@ +from functools import partial +import inspect + +from artiq.protocols.pc_rpc import simple_server_loop +from artiq.protocols.pc_rpc import Client as RPCClient + + +__all__ = ["RemoteExecServer", "RemoteExecClient", "simple_rexec_server_loop"] + + +class RemoteExecServer: + def __init__(self, target): + self.target = target + self.namespace = dict() + + def add_code(self, code): + exec(code, self.namespace) + + def call(self, function, *args, **kwargs): + return self.namespace[k](self, *args, **kwargs) + + +class RemoteExecClient(RPCClient): + def transfer_obj_source(self, obj): + self.add_code(self, inspect.getsource(obj)) + + +def simple_rexec_server_loop(target_name, target, host, port, + description=None): + targets = { + target_name: target, + target_name + "_rexec": lambda: RemoteExecServer(target) + } + simple_server_loop(targets, host, port, description)