mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 03:08:27 +08:00
protocols: add remote_exec
This commit is contained in:
parent
0d7d584f08
commit
e6809397a3
34
artiq/protocols/remote_exec.py
Normal file
34
artiq/protocols/remote_exec.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user