|
16 | 16 | import asyncio
|
17 | 17 | import argparse
|
18 | 18 | import os
|
| 19 | +import warnings |
| 20 | +import socket |
19 | 21 |
|
20 | 22 | logger = logging.getLogger(__name__)
|
21 | 23 |
|
|
51 | 53 | # Create the global agent state instance
|
52 | 54 | _global_agent_state = AgentState()
|
53 | 55 |
|
| 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 | + |
54 | 69 | async def stop_agent():
|
55 | 70 | """Request the agent to stop and update UI with enhanced feedback"""
|
56 | 71 | global _global_agent_state, _global_browser_context, _global_browser
|
@@ -538,6 +553,7 @@ async def run_with_stream(
|
538 | 553 | "Base": Base()
|
539 | 554 | }
|
540 | 555 |
|
| 556 | +@suppress_connection_reset |
541 | 557 | async def close_global_browser():
|
542 | 558 | global _global_browser, _global_browser_context
|
543 | 559 |
|
@@ -853,6 +869,9 @@ def list_recordings(save_recording_path):
|
853 | 869 | return demo
|
854 | 870 |
|
855 | 871 | def main():
|
| 872 | + # Suppress asyncio connection reset warnings |
| 873 | + warnings.filterwarnings("ignore", message=".*forcibly closed.*") |
| 874 | + |
856 | 875 | parser = argparse.ArgumentParser(description="Gradio UI for Browser Agent")
|
857 | 876 | parser.add_argument("--ip", type=str, default="127.0.0.1", help="IP address to bind to")
|
858 | 877 | parser.add_argument("--port", type=int, default=7788, help="Port to listen on")
|
|
0 commit comments