Skip to content

[core] Add a warning when returning an object w/ num_returns=0 #51826

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

13 changes: 13 additions & 0 deletions python/ray/_raylet.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import time
import traceback
import _thread
import typing
import warnings
from typing import (
Any,
AsyncGenerator,
Expand Down Expand Up @@ -4379,6 +4380,18 @@ cdef class CoreWorker:
num_returns = returns[0].size()

if num_returns == 0:
if num_outputs_stored is not None:
# If num_returns=0, it is likely a mistake to return a non-None object.

task_name = CCoreWorkerProcess.GetCoreWorker().GetCurrentTaskName()

task_num_returns_warning = (
"Task {} has num_returns=0 but returned a non-None value {}. "
"The return value will be ignored.\n"
).format(task_name, repr(num_outputs_stored))

warnings.warn(task_num_returns_warning)

return num_outputs_stored

task_output_inlined_bytes = 0
Expand Down