Daemon¶
A persistent background process that keeps a CarverSession (and with it the CUDA context and the compiled Warp kernels) alive for low-latency calls from Grasshopper or other clients. It communicates via Python's multiprocessing.connection over localhost; clients authenticate with a random key stored in ~/.urbansolarcarver/.daemon_authkey.
The daemon is started and stopped via the CLI (urbansolarcarver daemon start/stop, daemon status to check it) or from within Grasshopper using the USC_Session component. It binds to 127.0.0.1 only and is not reachable from the network.
A transport over the engine requests¶
The daemon only carries messages. Each request is a dict with a cmd key; the daemon passes it to engine_requests.answer_engine_message, which runs it and returns the reply dict, with status "ok" or "error". The commands, their keys and their replies are described in Engine requests. The daemon itself handles one more command, shutdown, which stops it.
Clients reach it through daemon_client.py, which uses only the standard library: resolve_daemon_authkey reads (or creates) the key and send_daemon_request sends one request, so asking the daemon something does not load torch. Grasshopper keeps its own copy of the key reading in usc_gh.py, because Rhino's Python does not import this package.
A message the daemon cannot unpickle gets an error reply too, and the daemon keeps running. Failed requests are logged with their traceback in the daemon's console or log file.
urbansolarcarver.daemon
¶
Long-running server that keeps a GPU session alive between pipeline calls.
Used by the Grasshopper components and the CLI --daemon flag. Starts a
single CarverSession and listens on a multiprocessing.connection
Listener for request dicts such as {"cmd": "run", "produce": [...], ...}.
The daemon is a transport: each request goes to
:func:urbansolarcarver.engine_requests.answer_engine_message, which runs it
and returns the reply dict ("status" is "ok" or "error") that is
sent back. Only shutdown is handled here, since it stops the transport.
Security assumptions
- Localhost only: the daemon binds to the loopback interface. Host names that do not resolve to 127.0.0.1 or ::1 are rejected at startup.
- Authkey: 32 random bytes, stored as 64 hex characters in
~/.urbansolarcarver/.daemon_authkey, are generated on first use. Clients must present this key. - Pickle IPC:
multiprocessing.connectionuses pickle internally. Any process that holds the authkey can execute arbitrary code in the daemon's context. This is acceptable because both endpoints run on the same machine under the same user account. - Not designed for multi-user or server deployment. Do not expose the daemon port to a network.
serve(address, authkey, device_arg='auto')
¶
Serve pipeline requests from Grasshopper and the CLI until "shutdown".
Keeps one CarverSession (CUDA context and compiled Warp kernels) alive
across requests. The commands are those of :mod:engine_requests, plus
shutdown. Requests are handled one at a time; a failing request
becomes an error reply and the server keeps running.