Generator that might return 1 value

How severe does this issue affect your experience of using Ray?

  • High: It blocks me to complete my task.

hey,
I’ve used the generators to create a list of references to avoid this anti-pattern : Anti-pattern: Returning ray.put() ObjectRefs from a task harms performance and fault tolerance — Ray 2.9.1

my returns are dynamic and i know the number of expected returns before the task starts,
which from what i understood in the documents, its preferable to use “options(num_returns=num_of_returns)” instead of “ray.method(num_returns=“dynamic”)”,
also noticed dynamic is soft deprecated…

the problem is that if the number of returns is 1, it does not return an iterable object…

take this code for example :

@ray.remote
class Test:

def generator(self, first_count, second_count):
    for fr in range(first_count):
        for sc in range(second_count):
            yield fr, sc

def main():
first_count = 1
second_count = 1
t = Test.remote()
t_ret = t.generator.options(num_returns=first_count*second_count).remote(first_count, second_count)
print(t_ret)
it = iter(t_ret)
for fr in range(first_count):
for sc in range(second_count):
print(ray.get(next(it)))

if name == “main”:
ray.init()
main()

it will fail on “TypeError: ‘ray._raylet.ObjectRef’ object is not iterable”

do i need to check num_returns > 1 before expecting and iterable ? is this the expected behavior ?

also note that normal pyhton generator with “yield” does work with 1 return,
as well as num_returns=“dynamic”

*edit: tried to fix the block quote with no success