Implementation:LMCache LMCache Runtime Plugin Launcher
| Knowledge Sources | |
|---|---|
| Domains | Plugin System, Process Management |
| Last Updated | 2026-02-09 00:00 GMT |
Overview
RuntimePluginLauncher discovers and launches external plugin scripts (Python or Bash) as subprocess alongside the LMCache engine.
Description
This class manages the lifecycle of runtime plugins defined in the engine configuration. It scans configured file paths or directories for .py and .sh files, applies role-based and worker-ID-based filtering using filename conventions (e.g., WORKER_0_myplugin.py), determines the interpreter from shebang lines or file extensions, and launches each plugin as a subprocess with environment variables containing the role, config JSON, worker count, and worker ID. A daemon thread captures each plugin's stdout and logs it. Plugins are automatically terminated on process exit via an atexit handler. The launcher gracefully handles missing interpreters by trying fallback options and skipping unsupported file types.
Usage
Use this launcher when the LMCache configuration specifies runtime_plugin_locations. It is instantiated during engine initialization and automatically launches all matching plugins. Call stop_plugins() to terminate all running plugin processes.
Code Reference
Source Location
- Repository: LMCache
- File: lmcache/v1/plugin/runtime_plugin_launcher.py
- Lines: 1-184
Signature
class RuntimePluginLauncher:
def __init__(self, config, role: str, worker_count: int, worker_id: int): ...
def launch_plugins(self): ...
def stop_plugins(self): ...
Import
from lmcache.v1.plugin.runtime_plugin_launcher import RuntimePluginLauncher
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config | LMCacheEngineConfig | Yes | Engine configuration containing runtime_plugin_locations |
| role | str | Yes | Current instance role (e.g., "worker", "scheduler") |
| worker_count | int | Yes | Total number of workers in the deployment |
| worker_id | int | Yes | ID of the current worker, used for plugin filtering |
Outputs
| Name | Type | Description |
|---|---|---|
| plugin_processes | list[subprocess.Popen] | List of launched plugin subprocess handles |
Plugin Naming Convention
Plugins are filtered by filename parts separated by underscores:
- First part: role filter (e.g.,
WORKER,SCHEDULER,ALL) - Second part (optional, if numeric): worker ID filter
- Example:
WORKER_0_my_plugin.pyruns only on worker 0 with role "worker"
Environment Variables
Plugins receive the following environment variables:
| Variable | Description |
|---|---|
| LMCACHE_RUNTIME_PLUGIN_ROLE | Current instance role |
| LMCACHE_RUNTIME_PLUGIN_CONFIG | JSON-serialized engine configuration |
| LMCACHE_RUNTIME_PLUGIN_WORKER_COUNT | Total worker count |
| LMCACHE_RUNTIME_PLUGIN_WORKER_ID | Current worker ID |
Usage Examples
from lmcache.v1.plugin.runtime_plugin_launcher import RuntimePluginLauncher
launcher = RuntimePluginLauncher(
config=config,
role="worker",
worker_count=4,
worker_id=0,
)
# Launch all configured plugins
launcher.launch_plugins()
# Later, stop all plugins
launcher.stop_plugins()