_drain_remaining_stderr() — langchain Function Reference
Architecture documentation for the _drain_remaining_stderr() function in shell_tool.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 2c92ef14_d880_f149_5132_20d7d028b5b7["_drain_remaining_stderr()"] cf4eeaa4_4bcc_69d9_a0f3_664b1eecb4e8["ShellSession"] 2c92ef14_d880_f149_5132_20d7d028b5b7 -->|defined in| cf4eeaa4_4bcc_69d9_a0f3_664b1eecb4e8 89d586a2_0b74_ac5c_97da_a6a18a02f59d["_collect_output()"] 89d586a2_0b74_ac5c_97da_a6a18a02f59d -->|calls| 2c92ef14_d880_f149_5132_20d7d028b5b7 style 2c92ef14_d880_f149_5132_20d7d028b5b7 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/langchain/agents/middleware/shell_tool.py lines 424–453
def _drain_remaining_stderr(
self, collected: list[str], deadline: float, drain_timeout: float = 0.05
) -> None:
"""Drain any stderr output that arrived concurrently with the done marker.
The stdout and stderr reader threads run independently. When a command writes to
stderr just before exiting, the stderr output may still be in transit when the
done marker arrives on stdout. This method briefly polls the queue to capture
such output.
Args:
collected: The list to append collected stderr lines to.
deadline: The original command deadline (used as an upper bound).
drain_timeout: Maximum time to wait for additional stderr output.
"""
drain_deadline = min(time.monotonic() + drain_timeout, deadline)
while True:
remaining = drain_deadline - time.monotonic()
if remaining <= 0:
break
try:
source, data = self._queue.get(timeout=remaining)
except queue.Empty:
break
if data is None or source != "stderr":
continue
stripped = data.rstrip("\n")
collected.append(f"[stderr] {stripped}")
if data.endswith("\n"):
collected.append("\n")
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does _drain_remaining_stderr() do?
_drain_remaining_stderr() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py.
Where is _drain_remaining_stderr() defined?
_drain_remaining_stderr() is defined in libs/langchain_v1/langchain/agents/middleware/shell_tool.py at line 424.
What calls _drain_remaining_stderr()?
_drain_remaining_stderr() is called by 1 function(s): _collect_output.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free