code: def test_threaded_actor_generator(shutdown_only):
      ray.init()
  
      @ray.remote(max_concurrency=10)
      class Actor:
          def f(self):
              for i in range(30):
                  time.sleep(0.1)
                  yield np.ones(1024 * 1024) * i
  
      @ray.remote(max_concurrency=20)
      class AsyncActor:
          async def f(self):
              for i in range(30):
                  await asyncio.sleep(0.1)
                  yield np.ones(1024 * 1024) * i
  
      async def main():
          a = Actor.remote()
          asy = AsyncActor.remote()
  
          async def run():
              i = 0
              async for ref in a.f.remote():
                  val = ray.get(ref)
                  print(val)
                  print(ref)
                  assert np.array_equal(val, np.ones(1024 * 1024) * i)
                  i += 1
                  del ref
  
          async def run2():
              i = 0
              async for ref in asy.f.remote():
                  val = await ref
                  print(ref)
                  print(val)
                  assert np.array_equal(
                      val, np.ones(1024 * 1024) * i
                  ), ref
                  i += 1
                  del ref
  
          coroutines = [run() for _ in range(10)]
          coroutines = [run2() for _ in range(20)]
  
          await asyncio.gather(*coroutines)
  
      asyncio.run(main())
  
imports: import asyncio
  import pytest
  import numpy
  import sys
  import time
  from collections import Counter
  from starlette.responses import StreamingResponse
  from starlette.requests import Request
  from fastapi import FastAPI
  from ray import serve
  from pydantic import BaseModel
  import ray
  from ray._raylet import ObjectRefGenerator
  from ray.exceptions import WorkerCrashedError
  from ray._private.test_utils import run_string_as_driver_nonblocking
  from ray.util.state import list_actors
label_desc: Use image node_id 1 for calling a global function with example usage: test_threaded_actor_generator(shutdown_only) without return types