Skip to content

Commit d1bafaf

Browse files
OhYeeCopilot
andauthored
Update agentrun/integration/builtin/sandbox.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent ef0a926 commit d1bafaf

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

agentrun/integration/builtin/sandbox.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -741,17 +741,24 @@ def _get_playwright(self, sb: BrowserSandbox) -> "BrowserPlaywrightSync":
741741
Automatically recreates the connection when the thread that created it has exited,
742742
because Playwright's internal greenlet is bound to the thread that created it.
743743
"""
744-
if (
745-
self._playwright_sync is not None
746-
and self._playwright_thread is not None
747-
and not self._playwright_thread.is_alive()
748-
):
749-
logger.debug(
750-
"Playwright creating thread (id=%s) has exited, recreating"
751-
" connection",
752-
self._playwright_thread.ident,
753-
)
754-
self._reset_playwright()
744+
if self._playwright_sync is not None and self._playwright_thread is not None:
745+
current_thread = threading.current_thread()
746+
creator_thread = self._playwright_thread
747+
if not creator_thread.is_alive() or current_thread is not creator_thread:
748+
if not creator_thread.is_alive():
749+
logger.debug(
750+
"Playwright creating thread (id=%s) has exited, recreating"
751+
" connection",
752+
creator_thread.ident,
753+
)
754+
else:
755+
logger.debug(
756+
"Playwright creating thread (id=%s) differs from current"
757+
" thread (id=%s), recreating connection",
758+
creator_thread.ident,
759+
current_thread.ident,
760+
)
761+
self._reset_playwright()
755762

756763
if self._playwright_sync is None:
757764
with self.lock:

0 commit comments

Comments
 (0)