[Python] How Ray async actors handle calls to sync methods

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with Ray async actors and I want to understand exactly what happens—at a deep technical level—when a synchronous method is called on such an actor.

    I know that calling a synchronous method will block, but am looking for clarity on how exactly this blocking occurs within the actor's architecture.

    As I see it, there are two possibilities:


    1. The event loop in the actor thread is preempted
      • The Ray async actor runs on a thread that hosts an asyncio event loop.
      • When the synchronous method is called, Ray's dispatcher invokes the sync method directly on that same thread, effectively pausing the event loop and running the sync method.
      • Once the sync method finishes, the event loop resumes.
      • This means the sync method blocks the thread by interrupting the event loop's execution.

    2. The event loop itself executes the synchronous method
      • The synchronous method is somehow wrapped as a coroutine/Future/Task and queued into the event loop's task queue.
      • The event loop picks it up and executes it within its normal flow.
      • The sync method’s blocking behavior causes the event loop itself to freeze until the sync method completes.
      • This means the blocking happens "inside" the event loop rather than as an external interruption.

    I'm looking for either an precise step-by-step explanation of what happens, or a reference to docs or the right parts of the source code.

    Continue reading...

Compartilhe esta Página