code: def test_detached_actor(ray_start_regular):
      @ray.remote
      class DetachedActor:
          def ping(self):
              return "pong"
  
      with pytest.raises(TypeError):
          DetachedActor._remote(lifetime="detached", name=1)
  
      with pytest.raises(
          ValueError, match="Actor name cannot be an empty string"
      ):
          DetachedActor._remote(lifetime="detached", name="")
  
      with pytest.raises(ValueError):
          DetachedActor._remote(
              lifetime="detached", name="hi", namespace=""
          )
  
      with pytest.raises(TypeError):
          DetachedActor._remote(
              lifetime="detached", name="hi", namespace=2
          )
  
      d = DetachedActor._remote(lifetime="detached", name="d_actor")
      assert ray.get(d.ping.remote()) == "pong"
  
      with pytest.raises(
          ValueError, match="Please use a different name"
      ):
          DetachedActor._remote(lifetime="detached", name="d_actor")
  
      address = ray_start_regular["address"]
  
      get_actor_name = "d_actor"
      create_actor_name = "DetachedActor"
      driver_script = """
  import ray
  ray.init(address="{}", namespace="default_test_namespace")
  
  name = "{}"
  assert ray.util.list_named_actors() == [name]
  existing_actor = ray.get_actor(name)
  assert ray.get(existing_actor.ping.remote()) == "pong"
  
  @ray.remote
  def foo():
      return "bar"
  
  @ray.remote
  class NonDetachedActor:
      def foo(self):
          return "bar"
  
  @ray.remote
  class DetachedActor:
      def ping(self):
          return "pong"
  
      def foobar(self):
          actor = NonDetachedActor.remote()
          return ray.get([foo.remote(), actor.foo.remote()])
  
  actor = DetachedActor._remote(lifetime="detached", name="{}")
  ray.get(actor.ping.remote())
  """.format(
          address, get_actor_name, create_actor_name
      )
  
      run_string_as_driver(driver_script)
      assert len(ray.util.list_named_actors()) == 2
      assert get_actor_name in ray.util.list_named_actors()
      assert create_actor_name in ray.util.list_named_actors()
      detached_actor = ray.get_actor(create_actor_name)
      assert ray.get(detached_actor.ping.remote()) == "pong"
      # Verify that a detached actor is able to create tasks/actors
      # even if the driver of the detached actor has exited.
      assert ray.get(detached_actor.foobar.remote()) == ["bar", "bar"]
  
imports: import os
  import sys
  import time
  import numpy
  import pytest
  import ray
  import ray._private.gcs_utils
  from ray.util.state import list_actors
  import ray.cluster_utils
  from ray._private.test_utils import SignalActor, convert_actor_state, kill_actor_and_wait_for_failure, make_global_state_accessor, run_string_as_driver, wait_for_condition, wait_for_pid_to_exit
  from ray._private.ray_constants import gcs_actor_scheduling_enabled
  from ray.experimental.internal_kv import _internal_kv_get, _internal_kv_put
label_desc: Use image node_id 17 for calling a global function with example usage: test_detached_actor(ray_start_regular) and returns: str