The registry.py module#
Summary#
One lane backend recorded in the registry. |
|
In-memory view of the on-disk registry. |
|
Outcome of |
|
Lanes removed and kept by |
|
Summary of |
Raised when the registry lock cannot be acquired in time. |
Return the per-user state directory, creating it if needed. |
|
Return the path to the registry JSON file. |
|
Return the path to the registry lock file. |
|
Hold the registry lock for the duration of the block. |
|
Delete the registry lock file. |
|
Read the registry from disk. |
|
Write the registry to disk atomically. |
|
Check whether a TCP connection to |
|
Check whether a process exists and is not a zombie. |
|
Kill a process and wait for it to exit. |
|
Kill a lane backend and its helpers but keep AEDT running. |
|
Kill a lane backend and remove it from the registry. |
|
Remove registry entries whose backend is no longer live. |
|
Clear every registry entry. |
|
Return the first port in range that is neither registered nor bound. |
|
Insert or replace one entry. |
|
Set the AEDT gRPC port of one entry. |
|
Remove one entry. |
|
Return one entry. |
|
Return every entry. |
Version of the on-disk registry format. |
|
Seconds to wait for the registry lock before giving up. |
|
Inclusive port range for lane backends. It avoids the default HTTP port 8080. |
|
Process name prefixes identifying AEDT, which must survive a lane recycle. |
Description#
File-backed registry of lane backends.
A lane is a long-lived ansys-aedt-mcp process serving the HTTP
transport on a loopback port. Each lane owns at most one AEDT session. The
registry records every running lane so that several MCP clients (IDE
windows, agents) can find and reuse the same backends.
The registry lives in a per-user state directory (%LOCALAPPDATA% on
Windows, $XDG_STATE_HOME on POSIX) and is guarded by a bounded-timeout
filelock.FileLock. A corrupt file is moved aside and replaced by an
empty registry, so every function here is safe to call from a recovery path.
Module detail#
- registry.state_dir() pathlib.Path#
Return the per-user state directory, creating it if needed.
- Returns:
pathlib.PathDirectory holding the registry, its lock file, and the lane logs.
- registry.registry_path() pathlib.Path#
Return the path to the registry JSON file.
- Returns:
pathlib.PathRegistry file path.
- registry.lockfile_path() pathlib.Path#
Return the path to the registry lock file.
- Returns:
pathlib.PathLock file path.
- registry.registry_lock(timeout: float | None = None) collections.abc.Iterator[None]#
Hold the registry lock for the duration of the block.
The OS releases the lock when its holder dies, even if the lock file stays on disk.
- Parameters:
- timeout
float,optional Seconds to wait for the lock. Defaults to
DEFAULT_LOCK_TIMEOUT.
- timeout
- Raises:
RegistryLockTimeoutErrorIf the lock is not acquired within
timeoutseconds.
- registry.force_unlock() bool#
Delete the registry lock file.
Use only when the lock is stuck and no legitimate holder exists. The registry file itself is left untouched.
- Returns:
- bool
Trueif a lock file was removed.
- registry.load_registry() Registry#
Read the registry from disk.
A missing file yields an empty registry. A corrupt file is backed up and replaced by an empty registry.
- Returns:
RegistryCurrent registry content.
- registry.save_registry(reg: Registry) None#
Write the registry to disk atomically.
The caller must hold
registry_lock().- Parameters:
- reg
Registry Registry to persist.
- reg
- registry.is_port_open(host: str, port: int, timeout: float = 0.3) bool#
Check whether a TCP connection to
host:portsucceeds.
- registry.kill_pid(pid: int, timeout: float = 10.0, tree: bool = True) bool#
Kill a process and wait for it to exit.
- Parameters:
- Returns:
- bool
Trueifpidis gone.
- registry.kill_keeping_aedt(pid: int, timeout: float = 10.0, keep_names: tuple[str, ...] = AEDT_PROCESS_PREFIXES) bool#
Kill a lane backend and its helpers but keep AEDT running.
AEDT processes and their children are spared. Every other process is killed alone and abruptly, so no exit handler can close AEDT.
- registry.stop_entry(server_id: str, timeout: float = 10.0) StopReport | None#
Kill a lane backend and remove it from the registry.
- registry.reap_registry(host: str = '127.0.0.1') ReapReport#
Remove registry entries whose backend is no longer live.
A lane is live when its process exists and its HTTP port accepts connections.
- Parameters:
- host
str, default: “127.0.0.1” Host the lanes listen on.
- host
- Returns:
ReapReportDropped and kept lane names.
- registry.reset_registry(kill_orphans: bool = False, unlock: bool = False) ResetReport#
Clear every registry entry.
- registry.allocate_http_port(reg: Registry, host: str = '127.0.0.1', port_range: tuple[int, int] = DEFAULT_HTTP_PORT_RANGE) int#
Return the first port in range that is neither registered nor bound.
The caller must hold
registry_lock(). The port is reserved only once an entry using it is saved.
- registry.upsert_entry(entry: ServerEntry) None#
Insert or replace one entry.
- Parameters:
- entry
ServerEntry Entry to store.
- entry
- registry.update_aedt_port(server_id: str, aedt_gpc_port: int | None) bool#
Set the AEDT gRPC port of one entry.
- registry.get_entry(server_id: str) ServerEntry | None#
Return one entry.
- registry.list_entries() list[ServerEntry]#
Return every entry.
- Returns:
list[ServerEntry]Registered lanes.
- registry.SCHEMA_VERSION = 1#
Version of the on-disk registry format.
- registry.DEFAULT_LOCK_TIMEOUT = 10.0#
Seconds to wait for the registry lock before giving up.
- registry.DEFAULT_HTTP_PORT_RANGE = (8090, 8189)#
Inclusive port range for lane backends. It avoids the default HTTP port 8080.
- registry.STATE_DIR_NAME = 'ansys-aedt-mcp'#
- registry.REGISTRY_FILENAME = 'registry.json'#
- registry.LOCKFILE_NAME = 'registry.lock'#
- registry.AEDT_PROCESS_PREFIXES = ('ansysedt',)#
Process name prefixes identifying AEDT, which must survive a lane recycle.