The WorkerState dataclass now supports lifecycle-aware and cloud-aware plugins: - Lifecycle fields: execution_mode, child_pids, container_id, conda_env - Cloud fields: is_remote, remote_resource
These fields are optional and only used when working with plugins from cjm-fasthtml-plugins that implement the LifecycleAwarePlugin or CloudAwarePlugin protocols.
Configuration Keys
Common configuration keys that indicate the plugin resource being used.
ResourceManager
The ResourceManager class tracks worker processes and provides methods to check resource availability and detect conflicts.
Manages resource tracking and conflict detection for the application. Tracks PIDs associated with application workers (transcription, LLM, etc.) and provides methods to check resource availability and conflicts. Enhanced to support lifecycle-aware and cloud-aware plugins from cjm-fasthtml-plugins.
Type
Default
Details
gpu_memory_threshold_percent
float
45.0
GPU memory usage threshold; external processes using more than this percentage are considered conflicts
Example: Basic Usage
# Create a resource managermanager = ResourceManager(gpu_memory_threshold_percent=45.0)# Register a workermanager.register_worker( pid=12345, worker_type="transcription", plugin_name="whisper", config={"model_id": "whisper-large-v3"})# Get worker infoworker = manager.get_worker_by_pid(12345)print(f"Worker type: {worker.worker_type}")print(f"Plugin: {worker.plugin_name}")print(f"Status: {worker.status}")# Update worker statemanager.update_worker_state(12345, status="running", job_id="job-123")worker = manager.get_worker_by_pid(12345)print(f"Updated status: {worker.status}")print(f"Job ID: {worker.job_id}")# Get worker by jobworker_by_job = manager.get_worker_by_job("job-123")print(f"Worker for job-123: PID {worker_by_job.pid}")# Check active worker typesprint(f"Active worker types: {manager.get_active_worker_types()}")# Unregister workermanager.unregister_worker(12345)print(f"Workers after unregister: {len(manager.get_all_workers())}")
Worker type: transcription
Plugin: whisper
Status: idle
Updated status: running
Job ID: job-123
Worker for job-123: PID 12345
Active worker types: {'transcription'}
Workers after unregister: 0
Worker PID: 12345
Execution mode: subprocess
Child PIDs: [99001, 99002, 99003]
All related PIDs: [12345, 99001, 99002, 99003]
All app PIDs (including children): [12345, 99001, 99002, 99003]
Example: Enhanced Usage with Lifecycle/Cloud Plugins
When using plugins from cjm-fasthtml-plugins, the resource manager automatically detects and tracks: - Child processes spawned by plugins - Cloud/remote resources - Container IDs and conda environments