-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: move playwright to thread to avoid event loop conflicts #353
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Changes requested. Reviewed everything up to ee322c1 in 1 minute and 22 seconds
More details
- Looked at
290
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
1
drafted comments based on config settings.
1. gptme/tools/_browser_thread.py:71
- Draft comment:
Ensure thatbrowser
is defined before attempting to close it. Ifsync_playwright().start()
orplaywright.chromium.launch()
fails,browser
will be undefined, leading to a potentialUnboundLocalError
. Consider initializingbrowser
toNone
before thetry
block and checking if it's notNone
before callingclose()
. - Reason this comment was not posted:
Comment did not seem useful.
Workflow ID: wflow_Q9EY13Rw3y4icFq7
Want Ellipsis to fix these issues? Tag @ellipsis-dev
in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
global _browser | ||
if _browser is None: | ||
logger.info("Starting browser thread") | ||
_browser = BrowserThread() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding error handling for the BrowserThread
initialization in get_browser()
. If BrowserThread
fails to start, it might raise an exception, which should be caught and logged appropriately.
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## master #353 +/- ##
==========================================
- Coverage 72.09% 71.03% -1.06%
==========================================
Files 67 68 +1
Lines 5132 5224 +92
==========================================
+ Hits 3700 3711 +11
- Misses 1432 1513 +81
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ee322c1
to
5673f4d
Compare
Resolves #351 by moving Playwright to a separate thread to isolate its event loop from prompt_toolkit. This prevents the asyncio.run() error that occurred when trying to use prompt_toolkit after browser operations. Changes: - Created thread-based browser manager - Updated all browser operations to use the thread - Added proper timeout and error handling Co-authored-by: Bob <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ Changes requested. Incremental review on 5673f4d in 51 seconds
More details
- Looked at
290
lines of code in2
files - Skipped
0
files when reviewing. - Skipped posting
0
drafted comments based on config settings.
Workflow ID: wflow_VaODCnWXYLf5uYTZ
Want Ellipsis to fix these issues? Tag @ellipsis-dev
in a comment. You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet
mode, and more.
Crazy how this entire thing was done by Bob! Just gave him the issue reference, had to question his choice of process/thread/eventloop, and then off he went! |
Fixes #351 by moving Playwright to a separate thread to isolate its event loop from prompt_toolkit.
This prevents the asyncio.run() error that occurred when trying to use prompt_toolkit after browser operations.
Changes:
Tested and confirmed working with:
Important
Moves Playwright operations to a separate thread using
BrowserThread
to prevent event loop conflicts withprompt_toolkit
.BrowserThread
to prevent event loop conflicts withprompt_toolkit
.BrowserThread
class in_browser_thread.py
to manage browser operations in a separate thread.read_url
,search_google
,search_duckduckgo
, andscreenshot_url
in_browser_playwright.py
to useBrowserThread
.read_url
,search
(Google and DuckDuckGo), andscreenshot_url
.prompt_toolkit
input works between operations.This description was created by for 5673f4d. It will automatically update as commits are pushed.