When using Ray application does not get executed

Hey, I am facing an issue when I used Ray tuner in my script, the script does not continue byeond the point that ray.init() is called. To make sure that the issue is not from my code I copied one of the examples from the docs and tried to execute it and the same issue occurred.

This is the code:
import time
import ray

ray.init()

@ray.remote
def do_some_work(x):
    time.sleep(1)  # Replace this is with work you need to do.
    return x

start = time.time()
results = [do_some_work.remote(x) for x in range(4)]
print("duration =", time.time() - start)
print("results = ", results)

When I run the program nothing gets printed. This is the command-line output:

(dl_env) G:\AI_projects\DL_Projects\ArabicText\ArabicText>python try_ray.py
2021-03-07 11:08:12,082 INFO services.py:1172 -- View the Ray dashboard at http://127.0.0.1:8265

(dl_env) G:\AI_projects\DL_Projects\ArabicText\ArabicText>

Moreover, there is a another issue, which is when I open the dashboard link it does not open and I get this from the browser: ‘This site can’t be reached’

This is my output with that code.

2021-09-05 16:23:22,436	INFO services.py:1263 -- View the Ray dashboard at http://127.0.0.1:8266
duration = 0.012996196746826172
results =  [ObjectRef(a67dc375e60ddd1affffffffffffffffffffffff0100000001000000), ObjectRef(63964fa4841d4a2effffffffffffffffffffffff0100000001000000), ObjectRef(69a6825d641b4613ffffffffffffffffffffffff0100000001000000), ObjectRef(ee4e90da584ab0ebffffffffffffffffffffffff0100000001000000)]
import sys; print('Python %s on %s' % (sys.version, sys.platform))
Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.25.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 7.25.0
Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
(pid=None) Traceback (most recent call last):
(pid=None)   File "c:\python38\lib\site-packages\ray\workers/default_worker.py", line 187, in <module>
(pid=None)     node = ray.node.Node(
(pid=None)   File "c:\python38\lib\site-packages\ray\node.py", line 223, in __init__
(pid=None)     self._metrics_export_port = self._get_cached_port(
(pid=None)   File "c:\python38\lib\site-packages\ray\node.py", line 662, in _get_cached_port
(pid=None)     ports_by_node.update(json.load(f))
(pid=None)   File "c:\python38\lib\json\__init__.py", line 293, in load
(pid=None)     return loads(fp.read(),
(pid=None)   File "c:\python38\lib\json\__init__.py", line 357, in loads
(pid=None)     return _default_decoder.decode(s)
(pid=None)   File "c:\python38\lib\json\decoder.py", line 337, in decode
(pid=None)     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
(pid=None)   File "c:\python38\lib\json\decoder.py", line 355, in raw_decode
(pid=None)     raise JSONDecodeError("Expecting value", s, err.value) from None
(pid=None) json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
2021-09-05 16:23:46,543	WARNING worker.py:1215 -- The node with node id: 24a3510412352ad5780a687308d7c655e4fc82f05609f031764bfa54 and ip: 10.14.0.12 has been marked dead because the detector has missed too many heartbeats from it. This can happen when a raylet crashes unexpectedly or has lagging heartbeats.

I also wasn’t able to connect to the dashboard (http://127.0.0.1:8266). I disabled the firewall and tested too. What’s going wrong?

Hi @DBraun,

The code snippet above is not waiting for the remote calls to finish or collecting the results before exiting.

You need to change it to either

refs = [do_some_work.remote(x) for x in range(4)]
results = ray.get(refs)

or

results = ray.get([do_some_work.remote(x) for x in range(4)])