refactor(exec_bridge): use weak session locks
This commit is contained in:
@@ -13,6 +13,7 @@ from collections import deque
|
|||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Awaitable, Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
from weakref import WeakValueDictionary
|
||||||
|
|
||||||
import typer
|
import typer
|
||||||
|
|
||||||
@@ -154,11 +155,11 @@ class CodexExecRunner:
|
|||||||
self.extra_args = extra_args
|
self.extra_args = extra_args
|
||||||
|
|
||||||
# Per-session locks to prevent concurrent resumes to the same session_id.
|
# Per-session locks to prevent concurrent resumes to the same session_id.
|
||||||
self._session_locks: dict[str, asyncio.Lock] = {}
|
self._session_locks: WeakValueDictionary[str, asyncio.Lock] = (
|
||||||
self._locks_guard = asyncio.Lock()
|
WeakValueDictionary()
|
||||||
|
)
|
||||||
|
|
||||||
async def _lock_for(self, session_id: str) -> asyncio.Lock:
|
async def _lock_for(self, session_id: str) -> asyncio.Lock:
|
||||||
async with self._locks_guard:
|
|
||||||
lock = self._session_locks.get(session_id)
|
lock = self._session_locks.get(session_id)
|
||||||
if lock is None:
|
if lock is None:
|
||||||
lock = asyncio.Lock()
|
lock = asyncio.Lock()
|
||||||
|
|||||||
Reference in New Issue
Block a user