code: def test_isolation(shutdown_only):
      info = ray.init(namespace="namespace")
  
      address = info["address"]
  
      # First param of template is the namespace. Second is the redis address.
      driver_template = """
  import ray
  
  ray.init(address="{}", namespace="{}")
  
  @ray.remote
  class DetachedActor:
      def ping(self):
          return "pong from other job"
  
  actor = DetachedActor.options(name="Pinger", lifetime="detached").remote()
  ray.get(actor.ping.remote())
      """
  
      # Start a detached actor in a different namespace.
      run_string_as_driver(driver_template.format(address, "different"))
  
      @ray.remote
      class Actor:
          def ping(self):
              return "pong"
  
      # Create an actor. This should succeed because the other actor is in a
      # different namespace.
      probe = Actor.options(name="Pinger").remote()
      assert ray.get(probe.ping.remote()) == "pong"
      del probe
  
      # Wait for actor removal
      actor_removed = False
      for _ in range(50):  # Timeout after 5s
          try:
              ray.get_actor("Pinger")
          except ValueError:
              actor_removed = True
              # This means the actor was removed.
              break
          else:
              time.sleep(0.1)
  
      assert actor_removed, "This is an anti-flakey test measure"
  
      with pytest.raises(
          ValueError, match="Failed to look up actor with name"
      ):
          ray.get_actor("Pinger")
  
      # Now make the actor in this namespace, from a different job.
      run_string_as_driver(driver_template.format(address, "namespace"))
  
      detached_actor = ray.get_actor("Pinger")
      assert (
          ray.get(detached_actor.ping.remote()) == "pong from other job"
      )
  
      with pytest.raises(
          ValueError, match="The name .* is already taken"
      ):
          Actor.options(name="Pinger", lifetime="detached").remote()
  
file_path: ray/python/ray/tests/test_namespace.py
imports: import sys
  import time
  import pytest
  import ray
  from ray._private import ray_constants
  from ray._private.test_utils import get_error_message, init_error_pubsub, run_string_as_driver
  from ray.cluster_utils import Cluster
label_desc: Use image node_id 1 for calling a global function with example usage: test_isolation(shutdown_only) and returns: str