Problem with worker_process_setup_hook

I’m trying to use the new worker_process_setup_hook and for me it fails with:

  File "/home/milad/micromamba/envs/dev/lib/python3.8/site-packages/ray/", line 645, in remote
    return actor_cls._remote(args=args, kwargs=kwargs, **updated_options)
  File "/home/milad/micromamba/envs/dev/lib/python3.8/site-packages/ray/util/tracing/", line 385, in _invocation_actor_class_remote_span
    return method(self, args, kwargs, *_args, **_kwargs)
  File "/home/milad/micromamba/envs/dev/lib/python3.8/site-packages/ray/", line 929, in _remote
    serialized_runtime_env_info = get_runtime_env_info(
  File "/home/milad/micromamba/envs/dev/lib/python3.8/site-packages/ray/_private/", line 1591, in get_runtime_env_info
    proto_runtime_env_info.serialized_runtime_env = runtime_env.serialize()
  File "/home/milad/micromamba/envs/dev/lib/python3.8/site-packages/ray/runtime_env/", line 389, in serialize
    return json.dumps(
  File "/home/milad/micromamba/envs/dev/lib/python3.8/json/", line 234, in dumps
    return cls(
  File "/home/milad/micromamba/envs/dev/lib/python3.8/json/", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/home/milad/micromamba/envs/dev/lib/python3.8/json/", line 257, in iterencode
    return _iterencode(o, 0)
  File "/home/milad/micromamba/envs/dev/lib/python3.8/json/", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type function is not JSON serializable

I’ve tried various functions but it even fails with:

def foo():

Is this a known issue? Happens on both 2.5.1 and 2.6.1

1 Like

actually, seems to work when I pass it in ray.init() but not when I pass it in worker options. Is this intentional?

cc: @sangcho could you take a quick look? Thanks.

Yeah this is only working with ray.init right now. We are planning to support for worker options too, but I think it won’t be merged by Ray 2.8. I will raise a better error message in Ray 2.7.