Manage A Daemon Lifecycle
This tutorial uses handler to declare a local workstation,
inspect lifecycle status, and manage the daemon in a with block. It does not submit a
solve. The with block starts and connects the daemon, then stops it when the block ends.
The final explicit startup and shutdown calls show lifecycle control without a with block.
Set JCMROOT and ensure that the local daemon is available before you run the
tutorial from the tutorial root:
python execution_runtime/daemon/01_lifecycle/run.py
Python File
"""Start a local daemon and inspect its lifecycle status."""
import jcmsuite
from jcmsuite.daemon import Workstation
daemon = jcmsuite.daemon.handler()
daemon.resources.add(Workstation(hostname="localhost", n_threads=1))
print(daemon.lifecycle.status().started)
print(daemon.lifecycle.status().connected)
print(daemon.lifecycle.status().resource_count)
with daemon:
status = daemon.lifecycle.status()
print(daemon.lifecycle.status().started)
print(daemon.lifecycle.status().connected)
print(daemon.lifecycle.status().started)
print(daemon.lifecycle.status().connected)
daemon.lifecycle.startup()
print(daemon.lifecycle.status().connected)
daemon.lifecycle.shutdown()
print(daemon.lifecycle.status().connected)