Skip to navigation

nemo_gym.web.site_pool

View as MarkdownOpen in Claude

Site-stack lease boundary and in-process reader/writer scheduling.

Module Contents

Classes

NameDescription
LocalSiteLockPoolCoordinate shared readers and exclusive writers for configured sites.
SiteCapacityErrorA site already has its maximum number of concurrent sessions.
SiteConcurrencyLimitPoolCap concurrent sessions per site; tasks on other sites are unaffected.
SiteLease-
SitePool-
UnmanagedSitePoolUse externally configured sites without reset or isolation guarantees.
_LocalLeaseState-

API

class nemo_gym.web.site_pool.LocalSiteLockPool()

Coordinate shared readers and exclusive writers for configured sites.

Locks prevent concurrent tasks from mutating the same site stack; they do not reset or isolate site data. Cross-site tasks acquire all locks in one condition critical section, avoiding partial acquisition and deadlocks.

_READER_MUTATIONS
= frozenset({'read_only', 'session_only'})
_active
dict[str, _LocalLeaseState] = {}
_condition
= asyncio.Condition()
_readers
Counter[str] = Counter()
_writers
set[str] = set()
nemo_gym.web.site_pool.LocalSiteLockPool._can_acquire(
sites: tuple[str, ...],
access: str
) -> bool
nemo_gym.web.site_pool.LocalSiteLockPool._sites(
) -> tuple[str, ...]
staticmethod
nemo_gym.web.site_pool.LocalSiteLockPool.acquire(
session_id: str,
async
nemo_gym.web.site_pool.LocalSiteLockPool.health() -> dict[str, typing.Any]
async
nemo_gym.web.site_pool.LocalSiteLockPool.release(
healthy: bool
) -> None
async
class nemo_gym.web.site_pool.SiteCapacityError()

Bases: RuntimeError

A site already has its maximum number of concurrent sessions.

class nemo_gym.web.site_pool.SiteConcurrencyLimitPool(
max_sessions_per_site: int
)

Cap concurrent sessions per site; tasks on other sites are unaffected.

Public sites rate-limit by client IP. When many rollouts share one egress IP, a burst of sessions on one site (GitHub, Hugging Face) triggers those limits and turns tasks into site-access failures. A full site rejects the seed instead of queueing it, so the caller retries later and the slot it would have held stays free for other sites.

_active
dict[str, tuple[str, ...]] = {}
_counts
Counter[str] = Counter()
_lock
= asyncio.Lock()
_rejected
= 0
nemo_gym.web.site_pool.SiteConcurrencyLimitPool.acquire(
session_id: str,
async
nemo_gym.web.site_pool.SiteConcurrencyLimitPool.health() -> dict[str, typing.Any]
async
nemo_gym.web.site_pool.SiteConcurrencyLimitPool.release(
healthy: bool
) -> None
async
class nemo_gym.web.site_pool.SiteLease(
lease_id: str,
isolated: bool,
metadata: dict[str, typing.Any] = dict()
)
Dataclass
isolated
bool
lease_id
str
metadata
dict[str, Any] = field(default_factory=dict)
class nemo_gym.web.site_pool.SitePool()
Protocol
nemo_gym.web.site_pool.SitePool.acquire(
session_id: str,
async
nemo_gym.web.site_pool.SitePool.health() -> dict[str, typing.Any]
async
nemo_gym.web.site_pool.SitePool.release(
healthy: bool
) -> None
async
class nemo_gym.web.site_pool.UnmanagedSitePool()

Use externally configured sites without reset or isolation guarantees.

_active
set[str] = set()
nemo_gym.web.site_pool.UnmanagedSitePool.acquire(
session_id: str,
async
nemo_gym.web.site_pool.UnmanagedSitePool.health() -> dict[str, typing.Any]
async
nemo_gym.web.site_pool.UnmanagedSitePool.release(
healthy: bool
) -> None
async
class nemo_gym.web.site_pool._LocalLeaseState(
sites: tuple[str, ...],
access: str
)
Dataclass
access
str
sites
tuple[str, ...]