Skip to content
Launch Platform

Running tasks in parallel (ray.get in a loop)

If your tasks run one at a time, you are probably calling eugo.hpc.get inside the loop that submits them. .remote(...) returns at once, but eugo.hpc.get waits for the result, so a get in the loop makes each task wait for the one before it. Submit every task first, then call eugo.hpc.get once on the whole list. Use eugo.hpc.wait to handle results as they finish, group tiny tasks into bigger ones, and share large inputs with eugo.hpc.put.

eugo.hpc is Ray's API under Eugo's name, so the same fix applies to ray.get in a loop.

Applies to: the EugoLab image, November 2026.

  • A notebook open in EugoLab.
  • A running cluster in the Eugo HPC Clusters panel.
  • The notebook connected to that cluster: on the cluster card, in the Notebook tab, select Connect this notebook. EugoLab adds and runs a two-line cell that connects the notebook. Connect before you run any task; otherwise the work runs on a private local Ray inside the notebook, not on the cluster. Connecting a notebook to your cluster explains what Connect does and how to check the connection.

.remote(...) returns at once with an ObjectRef, a reference to a result that may not exist yet. eugo.hpc.get blocks until that result is ready. With a list of references, it waits for all of them and returns the results in the same order as the list.

  1. In a new cell, define the function once with @eugo.hpc.distribute:

    import time
    import eugo.hpc
    @eugo.hpc.distribute
    def slow_square(x):
    time.sleep(0.5)
    return x * x
  2. This loop is the slow pattern. Each eugo.hpc.get waits for its task before the next task is submitted, so the tasks run one after another:

    results = []
    for i in range(100):
    results.append(eugo.hpc.get(slow_square.remote(i))) # waits every time
  3. This is the fast pattern. Submit every task, then call eugo.hpc.get once on the list. The tasks run at the same time, as far as the cluster's free CPUs allow:

    refs = [slow_square.remote(i) for i in range(100)] # returns at once
    results = eugo.hpc.get(refs) # waits once, results in order
    print(results[:5])
    [0, 1, 4, 9, 16]

Define a remote function once and reuse it. Calling eugo.hpc.distribute(fn) inside a loop makes and exports a new remote function each time, which Ray lists as an anti-pattern.

eugo.hpc.wait(refs, num_returns=k, timeout=s) returns two lists, (ready, not_ready), as soon as k results are done or the timeout passes.

  1. Submit the tasks, then take each result as soon as it is ready:

    refs = [slow_square.remote(i) for i in range(10)]
    while refs:
    ready, refs = eugo.hpc.wait(refs, num_returns=1)
    print(eugo.hpc.get(ready[0]))

    The results print in the order the tasks finish, which need not be the order you submitted them.

Each task has a fixed scheduling cost. When the work in a task is smaller than that cost, group the work so each task does more.

  1. Send a chunk of inputs to each task instead of one value:

    @eugo.hpc.distribute
    def square_chunk(xs):
    return [x * x for x in xs]
    chunks = [list(range(i, i + 1000)) for i in range(0, 100_000, 1000)]
    results = eugo.hpc.get([square_chunk.remote(c) for c in chunks])
    print(len(results), len(results[0]))
    100 1000

    The cell runs 100 tasks of 1,000 inputs each instead of 100,000 tasks of one input.

How do I share a large input between tasks?

Section titled “How do I share a large input between tasks?”

eugo.hpc.put(value) stores a value once in the cluster's object store and returns a reference. Pass the reference to every task instead of the value, so the value is not copied once per task.

  1. Store the array once, then pass its reference:

    import numpy as np
    big = np.random.rand(10_000, 1_000)
    big_ref = eugo.hpc.put(big)
    @eugo.hpc.distribute
    def column_mean(arr, col):
    return arr[:, col].mean()
    means = eugo.hpc.get([column_mean.remote(big_ref, c) for c in range(100)])
    print(len(means))
    100

    A reference passed as a task argument arrives in the task as the value itself, so column_mean receives the array, not the reference. Memory for distributed jobs explains the object store and how big it is.

A function decorated with @eugo.hpc.distribute(num_cpus=2) reserves 2 CPUs for each call (the default is 1). How many tasks run at the same time is bounded by the cluster's free CPUs.

  1. Check the cluster's free resources:

    eugo.hpc.available_resources()

    The result is a dictionary. Its CPU entry is the number of CPUs free right now, and a cluster with GPU workers also has a GPU entry.

  2. To run more at once, lower num_cpus for a light task, or give the cluster more or larger workers (see Cluster settings).

This notebook is already running Ray, started by a cell rather than through Connect

Section titled “This notebook is already running Ray, started by a cell rather than through Connect”

Cause: a cell ran work before you connected, so the notebook started its own Ray. The cluster card offers Disconnect instead of Connect this notebook, with this message as its tooltip.

Fix:

  1. Stop the notebook's own Ray: on the cluster card, select Disconnect, or restart the notebook's kernel.
  2. On the cluster card, in the Notebook tab, select Connect this notebook.
  3. Run your task cells again.

My tasks ran in the notebook, not on the cluster

Section titled “My tasks ran in the notebook, not on the cluster”

Cause: without Connect, the first call that runs work (.remote(...), eugo.hpc.put or eugo.hpc.get) starts a private local Ray inside the notebook.

Fix:

  1. Stop the notebook's own Ray: on the cluster card, select Disconnect, or restart the notebook's kernel.
  2. On the cluster card, in the Notebook tab, select Connect this notebook.
  3. Run your task cells again.

Error: eugo.hpc.use_auth_token_file: cannot use the Ray token file

Section titled “Error: eugo.hpc.use_auth_token_file: cannot use the Ray token file”

The full message names the file and ends in "it does not exist", "it is a folder, not a file" or "this process is not allowed to read it".

Cause: the connect code was copied before an update, or before the lab restarted.

Fix:

  1. On the cluster card, in the Notebook tab, select Copy code.
  2. Paste the code into the notebook and run it.

If the notebook is already connected, the call raises RuntimeError: eugo.hpc.use_auth_token_file: this process is connected to Ray; call eugo.hpc.shutdown() first. Run eugo.hpc.shutdown(), then run the new code.

© 2026 Eugo Inc. · Third-party licenses · LinkedIn (opens in new tab) · YouTube (opens in new tab) · GitHub (opens in new tab)