Skip to content

Commit

Permalink
fixes test_session.TestSingleSessions
Browse files Browse the repository at this point in the history
Signed-off-by: Teo <[email protected]>
  • Loading branch information
teocns committed Nov 12, 2024
1 parent a7e527f commit bfca31a
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions agentops/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,8 @@ def _enqueue(self, event: dict) -> None:

def _publish(self):
"""Notify the ChangesObserverThread to perform the API call."""
self.conditions["changes"].notify()
with self.conditions["changes"]: # Acquire the lock before notifying
self.conditions["changes"].notify()

def stop(self) -> None:
"""
Expand Down Expand Up @@ -799,19 +800,17 @@ def run(self) -> None:
logger.debug(f"{self.__class__.__name__}: started")
while not self.stopping:
try:
# Use a shorter timeout and don't hold the lock continuously
time.sleep(0.1)
# Wait for explicit notification instead of continuous polling
with self.s.conditions["changes"]:
# Use wait with timeout to allow checking stopping condition
self.s.conditions["changes"].wait(timeout=0.5)

if self.stopping:
logger.debug(f"{self.__class__.__name__} stopping (pre-lock)")
break

# Quick check with lock
# Only update if explicitly notified (not due to timeout)
with self.s._locks["session"]:
if self.s._events and not self.stopping:
logger.debug(
f"{self.__class__.__name__}: Processing session changes"
)
if not self.stopping:
self.s.api.update_session()

except Exception as e:
Expand Down

0 comments on commit bfca31a

Please sign in to comment.