79503277

Date: 2025-03-12 10:29:05
Score: 0.5
Natty:
Report link

After digging further through Ray's documentation, orthogonal to J_H's answer, this is the style Ray seems to prefer and is the cleanest in my opinion:

import ray
import numpy as np

ray.init()

@ray.remote
def test_function(x):
    try:
        if np.random.rand() < 0.5:
            raise Exception
        return [x, x*x, "The day is blue"]
    except Exception:
        return None

futures = [test_function.remote(i) for i in range(10000)]

print(ray.get(futures))

And then the None entries can be dropped either in the list itself, or when importing into Pandas with .dropna().

Hopefully this helps someone in the future :)

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Ludger