unienv_interface.remote.server¶
Host environments, worlds, nodes and data transformations for remote clients.
RemoteServer
¶
RemoteServer(*, max_frame_size: int = wire.DEFAULT_MAX_FRAME_SIZE)
Serve registered objects to :class:RemoteClient connections.
Example::
with RemoteServer() as server:
server.register("sim", env) # or register_recursive() to also host its world and nodes
server.serve("tcp://0.0.0.0:7000") # blocks; or listen() in the background
Each registered root runs on its own worker thread, shared by every hosted object
with the same world; calls on them are executed there one at a time, in arrival
order, whichever client sent them. Only the methods in protocol.METHODS can be
called.
register
¶
register(name: str, obj: Hosted, *, close: bool = True, backend: Optional[ComputeBackend] = None, device: Optional[Any] = None) -> str
Host obj (an Env, World, WorldNode or DataTransformation) under name.
Only obj itself is exposed; use :meth:register_recursive to also expose
the world and nodes it is built from. Objects sharing a world (e.g. an env and
its world registered separately) run on the same worker. Registering an object
that is already hosted returns its existing name. With close=True the server
closes obj (on its worker) when it shuts down.
A DataTransformation has no backend of its own: backend / device
(default: numpy, no device) are where the source spaces and data of its
calls are rebuilt on the server. Other objects use their own.
register_recursive
¶
register_recursive(name: str, obj: Hosted, *, close: bool = True) -> str
Like :meth:register, but also expose everything obj is built from.
An env built on a WorldEnv also exposes name/world and name/node
(the root node), and every node exposes its world (<node name>/world, unless
already hosted) and its children as <node name>/<child>, so clients can
compose them in components mode. Objects already hosted keep their first name.
listen
¶
listen(address: str = 'tcp://127.0.0.1:0') -> str
Accept connections on address in the background; return the bound address.
address is tcp://host:port, unix:///path or ws://host:port
(the latter requires websockets, from the network extra).
serve
¶
serve(address: str = 'tcp://127.0.0.1:0') -> None
Listen on address and block until :meth:close (or Ctrl-C).
connect
¶
connect(**client_options: Any) -> RemoteClient
An in-process client over a :class:MemoryTransport (mainly for tests).
close
¶
close() -> None
Stop listening, drop every connection, close owned objects on their workers.