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
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 __init__(self, initial_namespace):
self.namespace = dict(initial_namespace)
def add_code(self, code):
exec(code, self.namespace)
def call(self, function, *args, **kwargs):
return self.namespace[function](self, *args, **kwargs)
class RemoteExecClient(RPCClient):
def transfer_obj_source(self, obj):
self.add_code(self, inspect.getsource(obj))
return self.namespace[function](*args, **kwargs)
def simple_rexec_server_loop(target_name, target, host, port,
description=None):
initial_namespace = {"controller_driver": target}
targets = {
target_name: target,
target_name + "_rexec": lambda: RemoteExecServer(target)
target_name + "_rexec": lambda: RemoteExecServer(initial_namespace)
}
simple_server_loop(targets, host, port, description)