Skip to content

Commit 095fe3f

Browse files
author
katiue
committed
suppress socket error
1 parent 00f5ea6 commit 095fe3f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/utils/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
from langchain_ollama import ChatOllama
1616
from langchain_openai import AzureChatOpenAI, ChatOpenAI
1717
import gradio as gr
18-
from src.browser.custom_context import CustomBrowserContext
1918

2019
def get_llm_model(provider: str, **kwargs):
2120
"""

webui.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import asyncio
1717
import argparse
1818
import os
19+
import warnings
20+
import socket
1921

2022
logger = logging.getLogger(__name__)
2123

@@ -51,6 +53,19 @@
5153
# Create the global agent state instance
5254
_global_agent_state = AgentState()
5355

56+
def suppress_connection_reset(func):
57+
async def wrapper(*args, **kwargs):
58+
try:
59+
return await func(*args, **kwargs)
60+
except ConnectionResetError:
61+
# Suppress the ConnectionResetError
62+
warnings.warn("Connection was reset. This is usually harmless.", RuntimeWarning)
63+
pass
64+
except socket.error as e:
65+
if e.winerror != 10054: # If it's not the specific connection reset error
66+
raise
67+
return wrapper
68+
5469
async def stop_agent():
5570
"""Request the agent to stop and update UI with enhanced feedback"""
5671
global _global_agent_state, _global_browser_context, _global_browser
@@ -538,6 +553,7 @@ async def run_with_stream(
538553
"Base": Base()
539554
}
540555

556+
@suppress_connection_reset
541557
async def close_global_browser():
542558
global _global_browser, _global_browser_context
543559

@@ -853,6 +869,9 @@ def list_recordings(save_recording_path):
853869
return demo
854870

855871
def main():
872+
# Suppress asyncio connection reset warnings
873+
warnings.filterwarnings("ignore", message=".*forcibly closed.*")
874+
856875
parser = argparse.ArgumentParser(description="Gradio UI for Browser Agent")
857876
parser.add_argument("--ip", type=str, default="127.0.0.1", help="IP address to bind to")
858877
parser.add_argument("--port", type=int, default=7788, help="Port to listen on")

0 commit comments

Comments
 (0)