Daemon Lifecycle
Use jcmsuite.daemon.handler() to get the
DaemonHandler for the active
SolverContext. Pass context= to select another
context. The handler manages daemon lifecycle state and resource declarations.
Open A Handler
Use a DaemonHandler as a context manager when one block must manage the daemon
connection:
import jcmsuite
daemon = jcmsuite.daemon.handler()
daemon.resources.add(jcmsuite.daemon.Workstation(hostname="localhost"))
with daemon:
result = jcmsuite.solve("project.jcmp")
When the with block begins, jcmsuite starts and connects the daemon. The handler is
active for the block. When the block ends, jcmsuite disconnects the handler and stops the
daemon.
Note
When the application makes many solve calls, place the daemon context manager around all of them. Do not open and close a daemon context for each solve call because each context startup and shutdown adds lifecycle overhead. The same context can cover solve calls for projects in different files.
If startup or connection fails, the context manager raises an exception. Check the selected context, daemon installation, resource declarations, and remote authentication before you retry.
Use explicit lifecycle calls when the DaemonHandler
must remain available for several operations:
daemon = jcmsuite.daemon.handler()
daemon.resources.add(jcmsuite.daemon.Workstation(hostname="localhost"))
daemon.lifecycle.startup()
result = jcmsuite.solve("project.jcmp")
daemon.lifecycle.shutdown()
startup() starts and connects the daemon.
shutdown() disconnects the handler
and releases daemon service resources. You can connect the handler again after shutdown.
Inspect Status
Call daemon.lifecycle.status() to inspect the status of the daemon:
status = daemon.lifecycle.status()
print(status.started)
print(status.connected)
print(status.resource_count)
started reports the daemon lifecycle state.
connected reports the handler connection state.
The DaemonResources collection contains
the configured resource declarations. The
daemon_payload contains backend status data when the
daemon provides it.
Select The Backend
The backend mode in the context or solve call determines whether jcmsuite uses the daemon.
The default backend mode is "auto". Therefore,
with daemon:
result = jcmsuite.solve("project.jcmp")
automatically uses the daemon. The same applies when the backend is "daemon". When the
backend is "local", jcmsuite does not use the daemon, even in a with daemon: context.
Use Resources and Queues next to declare a local, scheduler, or remote resource. Use Submit and Wait when you need to collect a submission later.
Continue to Resources and Queues for resource declarations and Submit and Wait for deferred collection. See the Manage A Daemon Lifecycle tutorial for a runnable local workflow.