Skip to content

fix(browser): register event loop on worker thread for stream_async#509

Open
wangwangbobo wants to merge 1 commit into
strands-agents:mainfrom
wangwangbobo:fix/browser-event-loop-thread
Open

fix(browser): register event loop on worker thread for stream_async#509
wangwangbobo wants to merge 1 commit into
strands-agents:mainfrom
wangwangbobo:fix/browser-event-loop-thread

Conversation

@wangwangbobo

Copy link
Copy Markdown
Contributor

Fixes #453

When strands dispatches _execute_async to a worker thread, the browser's event loop isn't available there, causing RuntimeError: There is no current event loop in thread.

Root cause:

  • Browser.__init__ creates an event loop on the main thread
  • _execute_async is a sync method, so strands dispatches it to a worker thread
  • The worker thread has no event loop → self._loop.run_until_complete() fails

Fix: Add asyncio.set_event_loop(self._loop) at the start of _execute_async so the browser's loop is registered on whatever thread runs the tool.

Changes: 1 file, +4 lines (≤10 line fix)

When strands dispatches _execute_async to a worker thread, the browser's
event loop isn't available there, causing 'RuntimeError: There is no
current event loop in thread'. Fix by calling asyncio.set_event_loop()
in _execute_async before nest_asyncio.apply().

Fixes strands-agents#453
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Browser tool fails when used with stream_async

1 participant