code: def get_pids(
      expected, deployment_name="D", app_name="default", timeout=30
  ):
      handle = serve.get_deployment_handle(deployment_name, app_name)
      refs = []
      pids = set()
      start = time.time()
      while len(pids) < expected:
          if len(refs) == 0:
              refs = [
                  handle.remote()._to_object_ref_sync()
                  for _ in range(10)
              ]
  
          done, pending = ray.wait(refs)
          for ref in done:
              try:
                  pids.add(ray.get(ref))
              except RayActorError:
                  # Handle sent request to dead actor before running replicas were updated
                  # This can happen because health check period = 1s
                  pass
          refs = list(pending)
          if time.time() - start >= timeout:
              raise TimeoutError("Timed out waiting for pids.")
      return pids
  
imports: import os
  import sys
  import time
  from collections import defaultdict
  import pytest
  import requests
  import ray
  from ray import serve
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.cluster_utils import Cluster
  from ray.exceptions import RayActorError
  from ray.serve._private.common import DeploymentID, ReplicaState
  from ray.serve._private.constants import SERVE_NAMESPACE
  from ray.serve._private.deployment_state import ReplicaStartupStatus
  from ray.serve._private.utils import get_head_node_id
  from ray.serve.context import _get_global_client
  from ray.serve.handle import RayServeHandle
  from ray.serve.schema import ServeDeploySchema
label_desc: Use image node_id 1 for calling a global function with example usage: get_pids(expected, deployment_name, app_name, timeout) and returns: pids