forked from M-Labs/artiq
1
0
Fork 0

protocols/remote_exec: simplify, use global namespace

This commit is contained in:
Sebastien Bourdeauducq 2016-04-02 22:44:27 +08:00
parent 101101bbc9
commit 1a288e07cc
1 changed files with 5 additions and 11 deletions

View File

@ -2,33 +2,27 @@ from functools import partial
import inspect import inspect
from artiq.protocols.pc_rpc import simple_server_loop 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"] __all__ = ["RemoteExecServer", "RemoteExecClient", "simple_rexec_server_loop"]
class RemoteExecServer: class RemoteExecServer:
def __init__(self, target): def __init__(self, initial_namespace):
self.target = target self.namespace = dict(initial_namespace)
self.namespace = dict()
def add_code(self, code): def add_code(self, code):
exec(code, self.namespace) exec(code, self.namespace)
def call(self, function, *args, **kwargs): def call(self, function, *args, **kwargs):
return self.namespace[function](self, *args, **kwargs) return self.namespace[function](*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, def simple_rexec_server_loop(target_name, target, host, port,
description=None): description=None):
initial_namespace = {"controller_driver": target}
targets = { targets = {
target_name: target, target_name: target,
target_name + "_rexec": lambda: RemoteExecServer(target) target_name + "_rexec": lambda: RemoteExecServer(initial_namespace)
} }
simple_server_loop(targets, host, port, description) simple_server_loop(targets, host, port, description)