Hello,
Here is an example code, where in the main part I set up an os.environ
which I need in my function, decorated with @ray.remote:
import os
import ray
ray.init()
@ray.remote
def f(x):
print (os.environ['MYTEST'])
return x * x
# let's set an environ variable
os.environ['MYTEST'] = 'testing'
futures = [f.remote(i) for i in range(4)]
print(ray.get(futures)) # [0, 1, 4, 9]
If I call f(i) without the decorations, I have access to os.environ[‘MYTEST’], with @ray.remote
I don’t.
Is there an elegant way to access “globals” from the main part of the code within ray-decorated functions? I can probably pass os.environ
as an argument to f(x) but it’s not that elegant.