code: def test_generator_max_returns(monkeypatch, shutdown_only):
      """
      Test when generator returns more than system limit values
      (100 million by default), it fails a task.
      """
      with monkeypatch.context() as m:
          # defer for 10s for the second node.
          m.setenv(
              "RAY_max_num_generator_returns",
              "2",
          )
  
          @ray.remote
          def generator_task():
              for _ in range(3):
                  yield 1
  
          @ray.remote
          def driver():
              gen = generator_task.remote()
              for ref in gen:
                  assert ray.get(ref) == 1
  
          with pytest.raises(ray.exceptions.RayTaskError):
              ray.get(driver.remote())
  
file_path: ray/python/ray/tests/test_streaming_generator_2.py
imports: import asyncio
  import pytest
  import numpy
  import sys
  import time
  import gc
  import ray
  from ray.experimental.state.api import list_actors
label_desc: Use image node_id 4 for calling a global function with example usage: test_generator_max_returns(monkeypatch, shutdown_only) without return types