Skip to content

⚡ Bolt: Prevent event loop blocking in frame image fetch - #94

Open
benpiper wants to merge 1 commit into
mainfrom
bolt-asyncio-sleep-707313536607418233
Open

⚡ Bolt: Prevent event loop blocking in frame image fetch#94
benpiper wants to merge 1 commit into
mainfrom
bolt-asyncio-sleep-707313536607418233

Conversation

@benpiper

@benpiper benpiper commented Jul 4, 2026

Copy link
Copy Markdown
Owner

💡 What

Replaced a synchronous time.sleep(1) with await asyncio.sleep(1) inside the get_frame_image asynchronous route handler in backend/main.py. Also removed an unused import time statement to clean up imports.

🎯 Why

In FastAPI, async def endpoints execute on the single main event loop thread. Calling a synchronous blocking function like time.sleep() halts the thread entirely, preventing the server from processing any other requests concurrently while waiting for the frame file to be generated. Using await asyncio.sleep() correctly yields execution back to the event loop, ensuring the application remains highly responsive and performant.

📊 Impact

Eliminates a massive concurrency bottleneck. Previously, fetching a frame image that took 30 seconds to generate would lock up the server completely for 30 seconds. Now, the server can handle unlimited concurrent requests while waiting for the file to be created.

🔬 Measurement

  1. Start the server and initiate an extraction or action that triggers get_frame_image.
  2. Simultaneously send multiple requests to other endpoints (like /api/auth/me).
  3. Observe that the other endpoints return immediately rather than hanging until the frame image is served.

PR created automatically by Jules for task 707313536607418233 started by @benpiper

Replaced blocking time.sleep() call with asyncio.sleep() in the get_frame_image async endpoint. This prevents the server from freezing and improves concurrency. Added journal entry to .jules/bolt.md.

Co-authored-by: benpiper <4343814+benpiper@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant