code: def test_override_max_retries(
      ray_start_cluster, override_max_retries
  ):
      cluster = ray_start_cluster
      cluster.add_node(num_cpus=1)
      max_retries = ray_constants.DEFAULT_TASK_MAX_RETRIES
      runtime_env = {}
      if override_max_retries:
          max_retries = 1
          runtime_env["env_vars"] = {
              "RAY_TASK_MAX_RETRIES": str(max_retries)
          }
          os.environ["RAY_TASK_MAX_RETRIES"] = str(max_retries)
      # Since we're setting the OS environment variable after the driver process
      # is already started, we need to set it a second time for the workers with
      # runtime_env.
      ray.init(cluster.address, runtime_env=runtime_env)
  
      try:
  
          @ray.remote
          class ExecutionCounter:
              def __init__(self):
                  self.count = 0
  
              def inc(self):
                  self.count += 1
  
              def pop(self):
                  count = self.count
                  self.count = 0
                  return count
  
          @ray.remote
          def f(counter):
              ray.get(counter.inc.remote())
              sys.exit(-1)
  
          counter = ExecutionCounter.remote()
          with pytest.raises(ray.exceptions.WorkerCrashedError):
              ray.get(f.remote(counter))
          assert ray.get(counter.pop.remote()) == max_retries + 1
  
          # Check max_retries override still works.
          with pytest.raises(ray.exceptions.WorkerCrashedError):
              ray.get(f.options(max_retries=0).remote(counter))
          assert ray.get(counter.pop.remote()) == 1
  
          @ray.remote
          def nested(counter):
              ray.get(f.remote(counter))
  
          # Check override works through nested tasks.
          with pytest.raises(ray.exceptions.RayTaskError):
              ray.get(nested.remote(counter))
          assert ray.get(counter.pop.remote()) == max_retries + 1
      finally:
          if override_max_retries:
              del os.environ["RAY_TASK_MAX_RETRIES"]
  
file_path: ray/python/ray/tests/test_reconstruction_2.py
imports: import os
  import sys
  import time
  import numpy
  import pytest
  import ray
  import ray._private.ray_constants
  from ray._private.internal_api import memory_summary
  from ray._private.test_utils import Semaphore, SignalActor, wait_for_condition
label_desc: Use image node_id 9 for calling a global function with example usage: test_override_max_retries(ray_start_cluster, override_max_retries) and returns: count