Skip to content

Blocking time.sleep() calls in async code paths stall the event loopΒ #1261

@MervinPraison

Description

@MervinPraison

Problem

Multiple time.sleep() calls exist in code paths that execute inside the async event loop. This blocks the entire event loop, preventing all other agents/tasks from making progress.

Principle violated: "Performance-first", "Async-safe by default"

Critical Locations in praisonaiagents/agent/execution_mixin.py

Line Call Context
956 time.sleep(0.5) After server start
959 time.sleep(0.1) Server wait polling loop
988 time.sleep(1) In loop()
997 time.sleep(1) In loop()
1056 time.sleep(0.5) After thread start
1061 time.sleep(1) In loop()

Impact

When running multiple agents concurrently via asyncio, a single time.sleep(1) freezes ALL agents for 1 second. The event loop cannot service any other coroutines during blocking sleep calls. In a 10-agent workflow with sequential sleeps, this compounds to seconds of wasted wall-clock time per iteration cycle.

Suggested Fix

  • Replace time.sleep() with await asyncio.sleep() in async contexts
  • For sync/async dual code paths, detect the running loop and dispatch accordingly
  • Server readiness should use asyncio.Event signaling instead of polling with sleep

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions