Runtime Lifecycle
Close, shutdown, and ownership rules for RLMesh clients, servers, and sandboxes.
RLMesh separates detaching a client from shutting down an endpoint. The process that created a server owns its lifetime; clients come and go without affecting it. Keeping the two operations distinct is what lets several clients share one environment endpoint, and what keeps a short-lived evaluation script from tearing down a long-lived server.
Clients detach
RemoteEnv.close() and RemoteVectorEnv.close() detach the client. They
release the connection but do not normally stop the server — another
client can connect afterwards, or the same script can reconnect later.
from rlmesh.numpy import RemoteEnv
with RemoteEnv("127.0.0.1:5555") as env:
observation, info = env.reset()
The context manager form calls close() on exit, so a client never
outlives the block that created it.
Servers shut down
Stopping an endpoint is a separate, deliberate action: call shutdown()
on the EnvServer you created. The typical pattern starts the server,
runs work against its address, and shuts down in a finally block so the
endpoint goes away even when the work fails:
server = rlmesh.EnvServer(env, host="127.0.0.1", port=0)
server.start()
try:
run_eval(server.address)
finally:
server.shutdown()
See Serving environments for the
full serving workflow, including the blocking serve() form.
Remote shutdown is opt-in
By default only the owning process can stop a server. Letting a remote client request shutdown is an owner-level decision made through server options:
options = rlmesh.ServeOptions(allow_remote_shutdown=True)
server = rlmesh.EnvServer(env, "127.0.0.1:5555", options=options)
Leave this off for shared endpoints. Enable it when a single evaluator owns the whole topology and should be able to wind it down from the client side.
Sandboxes own their session
Sandboxed environments invert the client rule. SandboxEnv.close() and
SandboxVectorEnv.close() stop the sandbox session they own, because
RLMesh started that session on your behalf. This is deliberately stronger
than RemoteEnv.close(): when the handle goes away, so does the isolated
process behind it.
See Sandboxed environments for when to reach for a sandbox instead of a plain remote connection.
Summary
| Call | Effect |
|---|---|
RemoteEnv.close() |
Detach the client; server keeps running. |
EnvServer.shutdown() |
Stop the endpoint you created. |
ServeOptions(allow_remote_shutdown=True) |
Permit clients to request shutdown. |
SandboxEnv.close() |
Stop the owned sandbox session. |