code: def test_run_driver_twice(ray_start_regular):
      # We used to have issue 2165 and 2288:
      # https://github.com/ray-project/ray/issues/2165
      # https://github.com/ray-project/ray/issues/2288
      # both complain that driver will hang when run for the second time.
      # This test is used to verify the fix for above issue, it will run the
      # same driver for twice and verify whether both of them succeed.
      address_info = ray_start_regular
      driver_script = """
  import ray
  import ray.train
  import ray.tune as tune
  import os
  import time
  
  def train_func(config):
      for i in range(2):
          time.sleep(0.1)
          ray.train.report(dict(timesteps_total=i, mean_accuracy=i+97))  # report metrics
  
  os.environ["TUNE_RESUME_PROMPT_OFF"] = "True"
  ray.init(address="{}", namespace="default_test_namespace")
  ray.tune.register_trainable("train_func", train_func)
  
  tune.run_experiments({{
      "my_experiment": {{
          "run": "train_func",
          "stop": {{"mean_accuracy": 99}},
          "config": {{
              "layer1": {{
                  "class_name": tune.grid_search(["a"]),
                  "config": {{"lr": tune.grid_search([1, 2])}}
              }},
          }},
          "local_dir": os.path.expanduser("~/tmp")
      }}
  }})
  print("success")
  """.format(
          address_info["address"]
      )
  
      for i in range(2):
          out = run_string_as_driver(driver_script)
          assert "success" in out
  
imports: import asyncio
  import os
  import subprocess
  import sys
  from pathlib import Path
  import psutil
  import pytest
  import ray
  import ray._private.ray_constants
  from ray._private.test_utils import Semaphore, check_call_ray, check_call_subprocess, kill_process_by_name, start_redis_instance, run_string_as_driver, run_string_as_driver_nonblocking, wait_for_children_of_pid, wait_for_children_of_pid_to_exit
  from ray._private.utils import detect_fate_sharing_support
label_desc: Use image node_id 5 for calling a global function with example usage: test_run_driver_twice(ray_start_regular) without return types