forked from M-Labs/artiq
1
0
Fork 0

protocols: add remote_exec

This commit is contained in:
Sebastien Bourdeauducq 2016-03-24 00:49:02 +08:00
parent 0d7d584f08
commit e6809397a3
1 changed files with 34 additions and 0 deletions

View File

@ -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)