Skip to content

Replace time.sleep with asyncio.sleep for async calls - #7503

Open
MaddipatlaChetan24 wants to merge 1 commit into
google:mainfrom
MaddipatlaChetan24:patch-1
Open

MaddipatlaChetan24 wants to merge 1 commit into
google:mainfrom
MaddipatlaChetan24:patch-1

Conversation

@MaddipatlaChetan24

@MaddipatlaChetan24 MaddipatlaChetan24 commented Oct 11, 2026 •

Copy link
Copy Markdown

Link to Issue or Description of Change

Problem: PlaywrightComputer.current_state() and highlight_mouse() use blocking time.sleep() calls inside async methods. Since this file runs directly on the ADK agent's asyncio event loop (no thread/executor offload), each time.sleep() freezes the entire event loop — not just the current coroutine — for its duration (0.5s per screenshot, 1s per mouse highlight), stalling any other concurrent work on the loop (e.g. the agent's live session streaming).

Solution: Replace both time.sleep() calls with await asyncio.sleep(), which yields control back to the event loop instead of blocking it.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

No existing unit tests cover this file.

Manual End-to-End (E2E) Tests:
Reproduced the stall with a minimal harness: a heartbeat() coroutine ticking every 0.1s run concurrently with a coroutine calling time.sleep(1) — the heartbeat showed a full 1-second gap between ticks. Re-ran with await asyncio.sleep(1) instead — ticks stayed evenly spaced at ~0.1s with no gap. Also verified the changed file parses correctly (ast.parse).

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

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.

2 participants