Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/predict_rlm/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ def async_tool_callback(self):
finally:
_TOOL_CALLBACK_GATES.reset(token)

def is_running(self) -> bool:
"""Whether a top-level execution currently holds the gate."""
with self._condition:
return self._running

def wait_until_idle(self, timeout: float | None = None) -> bool:
"""Block until no top-level execution holds the gate.

Returns ``True`` once the gate is idle, or ``False`` if ``timeout``
elapsed first. Callers must be on a different thread than the one
holding the gate (the executing worker), otherwise this deadlocks.
"""
with self._condition:
return self._condition.wait_for(lambda: not self._running, timeout)

def _acquire(self) -> None:
with self._condition:
while self._running:
Expand Down
Loading
Loading