-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add per-agent locking to send message (#2109)
- Loading branch information
Showing
6 changed files
with
92 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import asyncio | ||
from collections import defaultdict | ||
|
||
|
||
class PerAgentLockManager: | ||
"""Manages per-agent locks.""" | ||
|
||
def __init__(self): | ||
self.locks = defaultdict(asyncio.Lock) | ||
|
||
def get_lock(self, agent_id: str) -> asyncio.Lock: | ||
"""Retrieve the lock for a specific agent_id.""" | ||
return self.locks[agent_id] | ||
|
||
def clear_lock(self, agent_id: str): | ||
"""Optionally remove a lock if no longer needed (to prevent unbounded growth).""" | ||
if agent_id in self.locks: | ||
del self.locks[agent_id] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters