fix: Resolve asyncio event loop error and improve translate UI performance#222
Conversation
Fixed event loop binding issue where httpx.AsyncClient was shared across multiple asyncio.Runner instances. Each document now creates its own client within the runner's event loop context. This resolves the error: "Event object is bound to a different event loop" that occurred when processing the second file. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Removed the PDF preview (iframe) to improve page performance, while keeping the download button functionality. The PDF is still fetched server-side with session cookies to avoid authorization issues, but the base64 encoding and iframe rendering are removed. Changes: - Removed base64 import - Removed PDF preview expander with iframe - Kept download button with server-side fetch for authentication 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary of ChangesHello @NotYuSheng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug affecting multi-file processing on the translation page and delivers a notable performance boost to the user interface. The changes ensure robust handling of asynchronous operations and streamline the user experience by removing a resource-intensive feature that was causing slowdowns. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||
There was a problem hiding this comment.
Code Review
This pull request effectively resolves the asyncio event loop error by instantiating a new httpx.AsyncClient for each document, which is a good fix. The removal of the PDF preview for performance is also a sensible improvement. My review includes a critical suggestion to prevent resource leaks by properly closing the httpx.AsyncClient and a minor improvement for user-facing error messages.
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
User description
Summary
Fixed asyncio event loop error that caused the second file to fail on the translate page, and improved performance by removing the PDF preview feature.
Changes Made
httpx.AsyncClientwas shared across multipleasyncio.RunnerinstancesContext / Rationale
Bug Fix: When processing multiple files on the translate page, the second file would fail with the error: "Event object is bound to a different event loop". This occurred because a single
httpx.AsyncClientcreated at module level was being used across multipleasyncio.Runner()instances, each with their own event loop.Performance Improvement: The translate page was experiencing significant lag due to automatically fetching and base64-encoding PDFs for preview in iframes. By removing the preview feature and keeping only the download button, the page now loads much faster while maintaining full functionality.
Related Docs or References
General Checklist
PR Type
Bug fix, Enhancement
Description
Fix asyncio event loop error for multi-file processing
Remove PDF preview feature to improve performance
Create separate HTTP client per document processing
Keep download functionality with proper authentication
Diagram Walkthrough
File Walkthrough
6_translate_UI.py
Fix asyncio client and remove PDF previewfrontend/my_pages/6_translate_UI.py
httpx.AsyncClientand create per-document clients