forked from M-Labs/artiq
1
0
Fork 0

protocols/remote_exec: add connect_global_rpc

This commit is contained in:
Sebastien Bourdeauducq 2016-04-04 19:09:23 +08:00
parent 059836c591
commit 4ce00e3b7a
1 changed files with 17 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import inspect
from artiq.protocols.pc_rpc import simple_server_loop
__all__ = ["RemoteExecServer", "RemoteExecClient", "simple_rexec_server_loop"]
__all__ = ["RemoteExecServer", "simple_rexec_server_loop", "connect_global_rpc"]
class RemoteExecServer:
@ -29,3 +29,19 @@ def simple_rexec_server_loop(target_name, target, host, port,
target_name + "_rexec": lambda: RemoteExecServer(initial_namespace)
}
simple_server_loop(targets, host, port, description)
def connect_global_rpc(controller_rexec, host=None, port=3251,
target="master_dataset_db", name="dataset_db"):
if host is None:
host = controller_rexec.get_local_host()
code = """
if "{name}" not in controller_initial_namespace:
import atexit
from artiq.protocols.pc_rpc import Client
{name} = Client("{host}", {port}, "{target}")
atexit.register({name}.close_rpc)
controller_initial_namespace["{name}"] = {name}
""".format(host=host, port=port, target=target, name=name)
controller_rexec.add_code(code)