pythonasynchronousray

Python Ray - explanation of await queue.get_async(block=True, timeout=None)


Ray.util.queue.Queue.get_async has block argument. Why async method blocks as async means return without blocking, in my understanding.

Looked for an explanation in the user guide but not found a clue so far.


Solution

  • AFAIU from https://docs.ray.io/en/latest/_modules/ray/util/queue.html#Queue.get_async (also, I dived a bit deeper in that codebase), I came to conclusion that:

    1. yes, async means non-blocking, but this "block" argument serves for a bit another purpose;
    2. if you use block and queue is empty, it will wait until something appears in a queue or given timeout exceeded
    3. if you don't use block, then it will return immediately even if there is nothing in queue (it will raise en exception in this case).

    So, basically, that's it.