code: def test_background_tasks_with_max_calls(shutdown_only):
      ray.init(
          # TODO (Alex): We need to fix
          # https://github.com/ray-project/ray/issues/20203 to remove this flag.
          num_cpus=2,
          _system_config={"worker_cap_initial_backoff_delay_ms": 0},
      )
  
      num_tasks = 3 if sys.platform == "win32" else 10
  
      @ray.remote
      def g():
          time.sleep(0.1)
          return 0
  
      @ray.remote(max_calls=1, max_retries=0)
      def f():
          return [g.remote()]
  
      nested = ray.get([f.remote() for _ in range(num_tasks)])
  
      # Should still be able to retrieve these objects, since f's workers will
      # wait for g to finish before exiting.
      ray.get([x[0] for x in nested])
  
      @ray.remote(max_calls=1, max_retries=0)
      def f():
          return os.getpid(), g.remote()
  
      nested = ray.get([f.remote() for _ in range(num_tasks)])
      while nested:
          pid, g_id = nested.pop(0)
          assert ray.get(g_id) == 0
          del g_id
          # Necessary to dereference the object via GC, so the worker can exit.
          gc.collect()
          wait_for_pid_to_exit(pid)
  
imports: import gc
  import logging
  import os
  import sys
  import time
  import subprocess
  from unittest.mock import Mock, patch
  import unittest
  import pytest
  import ray
  import ray.cluster_utils
  from ray._private.test_utils import run_string_as_driver, wait_for_pid_to_exit, client_test_enabled
  from ray._private.resource_spec import HEAD_NODE_RESOURCE_NAME
label_desc: Use image node_id 1 for calling a global function with example usage: test_background_tasks_with_max_calls(shutdown_only) and returns: int, list, os,  g