code: def test_idle_workers(shutdown_only):
      ray.init(
          num_cpus=2,
          _system_config={
              "idle_worker_killing_time_threshold_ms": 10,
          },
      )
  
      @ray.remote(num_cpus=0)
      class Actor:
          def get(self):
              pass
  
      @ray.remote
      def getpid():
          time.sleep(0.1)
          return os.getpid()
  
      # We start exactly as many workers as there are CPUs.
      for _ in range(3):
          pids = set(ray.get([getpid.remote() for _ in range(4)]))
          assert len(pids) <= 2, pids
          # Wait for at least the idle worker timeout.
          time.sleep(0.1)
  
      # Now test with two actors that uses 1 process each but 0 CPUs.
      a1 = Actor.remote()
      a2 = Actor.remote()
      ray.get([a1.get.remote(), a2.get.remote()])
  
      for _ in range(3):
          pids = set(ray.get([getpid.remote() for _ in range(4)]))
          assert len(pids) <= 2, pids
          # Wait for at least the idle worker timeout.
          time.sleep(0.1)
  
      # Kill the actors and test again.
      del a1
      del a2
      for _ in range(3):
          pids = set(ray.get([getpid.remote() for _ in range(4)]))
          assert len(pids) <= 2, pids
          # Wait for at least the idle worker timeout.
          time.sleep(0.1)
  
file_path: ray/python/ray/tests/test_worker_capping.py
imports: import asyncio
  import os
  import pytest
  import sys
  import tempfile
  import time
  import ray
  from ray._private.test_utils import Semaphore
label_desc: Use image node_id 8 for calling a global function with example usage: test_idle_workers(shutdown_only) and returns: os