diff --git a/python/ray/services.py b/python/ray/services.py index 1b3cfd66e..31daf4754 100644 --- a/python/ray/services.py +++ b/python/ray/services.py @@ -472,6 +472,14 @@ def start_ui(redis_address, stdout_file=None, stderr_file=None, cleanup=True): new_notebook_directory = os.path.dirname(new_notebook_filepath) shutil.copy(notebook_filepath, new_notebook_filepath) port = 8888 + while True: + try: + port_test_socket = socket.socket() + port_test_socket.bind(("127.0.0.1", port)) + port_test_socket.close() + break + except OSError: + port += 1 new_env = os.environ.copy() new_env["REDIS_ADDRESS"] = redis_address command = ["jupyter", "notebook", "--no-browser",