File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -99,8 +99,8 @@ async def _handle_new_page(self, pw_page: Page):
9999 Uses the page switch lock to prevent race conditions with ongoing operations.
100100 """
101101 try :
102- # Use timeout to prevent indefinite blocking
103- async with asyncio . timeout ( 30 ):
102+ # Use wait_for for Python 3.10 compatibility (timeout prevents indefinite blocking)
103+ async def handle_with_lock ( ):
104104 async with self .stagehand ._page_switch_lock :
105105 self .stagehand .logger .debug (
106106 f"Creating StagehandPage for new page with URL: { pw_page .url } " ,
@@ -111,6 +111,8 @@ async def _handle_new_page(self, pw_page: Page):
111111 self .stagehand .logger .debug (
112112 "New page detected and initialized" , category = "context"
113113 )
114+
115+ await asyncio .wait_for (handle_with_lock (), timeout = 30 )
114116 except asyncio .TimeoutError :
115117 self .stagehand .logger .error (
116118 f"Timeout waiting for page switch lock when handling new page: { pw_page .url } " ,
Original file line number Diff line number Diff line change @@ -47,10 +47,12 @@ async def _ensure_page_stability(self):
4747 """Wait for any pending page switches to complete"""
4848 if hasattr (self ._stagehand , "_page_switch_lock" ):
4949 try :
50- # Use timeout to prevent indefinite blocking
51- async with asyncio . timeout ( 30 ):
50+ # Use wait_for for Python 3.10 compatibility (timeout prevents indefinite blocking)
51+ async def acquire_lock ( ):
5252 async with self ._stagehand ._page_switch_lock :
5353 pass # Just wait for any ongoing switches
54+
55+ await asyncio .wait_for (acquire_lock (), timeout = 30 )
5456 except asyncio .TimeoutError :
5557 # Log the timeout and raise to let caller handle it
5658 if hasattr (self ._stagehand , "logger" ):
You can’t perform that action at this time.
0 commit comments