Files
mattzh72--articraft/agent/runtime_limits.py
T
wehub-resource-sync 2c632336aa
CI / Viewer CI (push) Successful in 13m37s
CI / Core CI (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:32:38 +08:00

29 lines
708 B
Python

from __future__ import annotations
import asyncio
from contextlib import asynccontextmanager
from dataclasses import dataclass
from typing import AsyncIterator
@dataclass(slots=True)
class BatchRuntimeLimits:
local_work_semaphore: asyncio.Semaphore | None = None
@asynccontextmanager
async def local_work(self) -> AsyncIterator[None]:
if self.local_work_semaphore is None:
yield
return
async with self.local_work_semaphore:
yield
@asynccontextmanager
async def local_work_slot(limits: BatchRuntimeLimits | None) -> AsyncIterator[None]:
if limits is None:
yield
return
async with limits.local_work():
yield